AppleScripting text storage
AppleScripting text storage
- Subject: AppleScripting text storage
- From: John Nairn <email@hidden>
- Date: Fri, 12 Sep 2003 16:33:01 -0600
I am trying to make some text in my Cocoa app available to AppleScript.
I started by using the text scripting settings from the TextEdit
example app (with minor exceptions) in 3 steps:
1. Added to my ScriptSuite
"ToOneRelationships" = {
"cmdTextStorage" = {
"Type" = "NSTextSuite.NSTextStorage";
"AppleEventCode" = "ctxt";
};
2. Added to my ScriptTerminolgy
"ToOneRelationships" = {
"cmdTextStorage" = {
"Description" = "text of the commands";
"Name" = "commands";
};
3. Added accessor to my document class
- (NSTextStorage *)cmdTextStorage
{ return [oneTextView textStorage];
}
The only differences in my app from TextEdit example are
1. My text entity is called "cmdTextStorage" intead of "textStorage"
2. I did not use DefaultSubcontainerAttribute because I want more than
one text object (as several ToOneRelationships and not one
ToManyRelationships) and none should be default.
3. I named the relationship "commands" again because I want access to
more than one text storage and they can not all be called "text"
I then tried an AppleScript with following results
1. One-line script
display dialog commands of front document
This fails, but is also fails when scripting TextEdit
2. Set variable first instead
set cmds to commands of front document
display dialog cmds
Works as expected and all text is displayed. Also works in TextEdit.
3. Access piece of text (paragraph, word, etc.)
set cmds to paragraphs 2 of commands of front document
display dialog cmds
This fails with AppleScript error on first line of
NSCannotCreateScriptCommandError. The same AppleScript works fine,
however, in TextEdit (with "commands" replaced by "text" as named in
TextEdit terminology)
The current problem (and question, finally) is how come my app can not
access pieces of text while nearly identical methods in TextEdit
accomplishes the task just fine?
Future problems will be how to set text and pieces of text too, how to
have multiple text objects in the document (should be easy if I get one
working), and me understanding the essential differences between an
attribute and a ToOneRelationship. They seem very similar.
------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.eng.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.