Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / May 2004



Tip: Looking for answers? Try searching our database.

applescript, ide, change text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chad J McQuinn - 23 May 2004 01:26 GMT
I want to use an applescript to change some text in the frontmost
document window. The following works:

tell application "CodeWarrior IDE"
  activate
  set selection of document 1 to "hello world"
end tell

The following does *not*

tell application "CodeWarrior IDE"
  activate
  set selection of document 1 to (the clipboard as text)
end tell

Running this from script editor gives me an error dialog: "CodeWarrior
IDE got an error: Unknown object type."

Can someone tell me what I am doing wrong? I am running CW 8.3 on
Panther (10.3.3). I got the same result from running the ide in classic.

Thanks,
-Chad
MW Ron - 25 May 2004 18:29 GMT
>I want to use an applescript to change some text in the frontmost
>document window. The following works:
[quoted text clipped - 16 lines]
>Can someone tell me what I am doing wrong? I am running CW 8.3 on
>Panther (10.3.3). I got the same result from running the ide in classic.

Don't know about 8.3 but your script works in 10.3.3 with CW Pro 9.2 .

You might try moving the "the clipboard" command outside of the CW tell
block, like so:

-- begin script

set newText to the clipboard as text

tell application "CodeWarrior IDE"
   activate
   set selection of document 1 to newText
end tell

-- end script

that was a suggestion by one of our people.

Ron

Signature

 Metrowerks, one of the world¹s top 100 companies and influencers
    in the software development industry. - SD Times  May 2004
              http://www.sdtimes.com/2004sdt100.htm
     
                 Metrowerks, maker of CodeWarrior
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com

Chad J McQuinn - 25 May 2004 19:45 GMT
> Don't know about 8.3 but your script works in 10.3.3 with CW Pro 9.2 .
>
[quoted text clipped - 11 lines]
>
> -- end script

Ron,

Thanks so much for the reply. I tried moving the clipboard assignment
outside the tell block, but I received the same "Unknown Object Type"
error. The very strange thing is that it always works for literal
strings, and never works for strings that I pull in from the outside.
I.e.

-----
set thetext to "hello, world"
tell app "Codewarrior IDE" to set text of document 1 to thetext
-----

works just fine, but all of the following "set" statements preceding the
tell block don't work:

set thetext to the clipboard as text
set thetext to the clipboard as string
set thetext to (posix file "/Users" as string)

Following any of those by telling the ide to set the text or selection
of a document give the same unknown object type error. So it seems that
any coercion throws a wrench in the gears. FWIW the provided scripts to
create c++ class/header files fail with the same error. I'm quite
stumped.

So, perhaps this is a case where it's better to explain what I really
want to do instead. I want to run my source and header files through the
unix command "astyle". The only way I know of to run shell scripts
through the ide is to use applescript, or a post-linker. Post-linker
isn't a great solution, because that modifies the files right after they
are compiled. Applescript I can't get to work.

About the best thing I can come up with at this point is to use
applescript to enumerate the files in the project and call astyle on
them individually, but this has some problems. I'd be interested to know
if anyone else can think of a solution.

-Chad
Isaac Wankerl - 25 May 2004 21:18 GMT
> > Don't know about 8.3 but your script works in 10.3.3 with CW Pro 9.2 .
> >
[quoted text clipped - 18 lines]
> error. The very strange thing is that it always works for literal
> strings, and never works for strings that I pull in from the outside.

Ahh, this rings a bell now.  I think that the OS now says that this is
typeStyledText when it previously sent it as typeChar.  Since there is
no automatic conversion between the two and the IDE is only asking for
typeChar, the Apple Event fails.  Which IDE version are you using?  We
fixed this but I don't recall when it was done (maybe in the Pro 9 or
9.1 IDE).

> I.e.
>
[quoted text clipped - 29 lines]
>
> -Chad

You could use the COM API in the IDE for this and it won't have the
Apple Event problems you're running into.  I've got something I can send
you to help get you started if you want it.  Just send me an e-mail if
you do.

Signature

Isaac Wankerl
Metrowerks

Chad J McQuinn - 25 May 2004 22:14 GMT
> Ahh, this rings a bell now.  I think that the OS now says that this is
> typeStyledText when it previously sent it as typeChar.  Since there is
> no automatic conversion between the two and the IDE is only asking for
> typeChar, the Apple Event fails.  Which IDE version are you using?  We
> fixed this but I don't recall when it was done (maybe in the Pro 9 or
> 9.1 IDE).

Isaac,

Thanks for your response. I am using CW Pro 8.3 on OS 10.3.3. Do you
know if there's some way in applescript to do a manual conversion to
typeChar? I always thought that the "foo as text" stuff did the same
basic thing as AECoerceDesc.

> You could use the COM API in the IDE for this and it won't have the
> Apple Event problems you're running into.  I've got something I can send
> you to help get you started if you want it.  Just send me an e-mail if
> you do.

Sure, that would be great! It's been sent.

Thanks,
-Chad
Chad J McQuinn - 27 May 2004 02:10 GMT
> > Ahh, this rings a bell now.  I think that the OS now says that this is
> > typeStyledText when it previously sent it as typeChar.  Since there is
> > no automatic conversion between the two and the IDE is only asking for
> > typeChar, the Apple Event fails.
...
> Do you
> know if there's some way in applescript to do a manual conversion to
> typeChar? I always thought that the "foo as text" stuff did the same
> basic thing as AECoerceDesc.

To answer my own question here, the following applescript works correctly

-----
set thetext to «class ktxt» of ((the clipboard as text) as record)
tell application "CodeWarrior IDE"
  set text of document 1 to thetext
end tell
-----

where the first line is to work around the problem Isaac described. The
"«" and "»" characters around "class ktxt" are typed on a US keyboard
with "option-\" and "shift-option-\".

-Chad
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.