Cocoa AppleScript: selection, inserting?
Cocoa AppleScript: selection, inserting?
- Subject: Cocoa AppleScript: selection, inserting?
- From: Marcel Weiher <email@hidden>
- Date: Fri, 12 Oct 2001 17:23:17 +0200
Hi folks,
I am having a hard time with some aspects of scripting Cocoa apps using
AppleScript. Particularly:
1. dealing with the selection
2. inserting 'stuff'
I've been using TextEdit and Sketch as target apps.
Example 1:
Using Sketch, I create a rectangle and select it. Setting the
rectangle's x-position using:
tell application "Sketch"
set x position of graphic 1 of document 1 to 200
end tell
works fine. However, attempting to do this via the selection fails with
'NSReceiverEvaluationScriptError: 3'. Here are some examples that yield
this error (leaving out the tell-bracket)
set x position of selection to 200
set x position of selection of document 1 to 200
set x position of graphic 1 of selection to 200
set x position of graphic 1 selection of document 1 to 200
In fact, even just getting the selection using
set theSelection to selection
yields the same error. Using this particular snippet with the Finder,
for example, works fine, TextEdit has the same error.
Example 2:
Trying to insert text into a TextEdit document:
tell application "TextEdit"
make words with data "Hello World!" at beginning of text of document 1
end tell
Replace the entire document text. I would have expected it to insert
text at the beginning
make words with data "Hello World!" at end of text of document 1
returns an NSInternalScriptError
make words with data "Hello World!" at beginning of word 2 of text
of document 1
always inserts the text at the start of the document, no matter which
'word' was specified.
make words with data "Hello World!" at end of word 2 of text of
document 1
again yields an NSInternalScriptError.
Am I missing something? Is Cocoa AppleScripting not fully functional
yet?
Thanks,
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com