On May 22, 2007, at 10:35 PM, Jim DeVona wrote:
Can someone help me figure out how to access note text with
AppleScript? Here is a contrived example of what I'm trying to do:
tell application "Yojimbo"
set _item to make new note item with properties {name:"Foo",
contents:"Bar"}
set _text to contents of _item
end tell
I'd like to assign the "Bar" contents to the _text variable, but it
just gets another reference to the note item. I don't actually need to
put it all in a variable;
According to the Scripting Guidelines:
If an object’s contents can be represented as a single value, it
should define a contents property. For example, documents in a word
processor would define a contents property that returned all the
text as a string. contents is usually writable.
For this reason, Yojimbo note items have a property named "contents".
The problem you are running into is because you have a variable which
contains a reference (specifier) to the note item.
AppleScript treats "contents of" specially when operating on variables.
set x to 3
contents of x
-- 3
If x is a reference/specifier to an object, then sometimes
AppleScript will automatically dereference the variable for you.
tell application "Script Editor"
set d to document 2
name of d
-- "My Fancy Script"
name of contents of d
-- "My Fancy Script"
end tell
But AppleScript doesn't do the implicit dereferencing when asking for
the contents property (because of the semantics in the first example.)
tell application "Script Editor"
set d to document 2
name of d
-- "My Fancy Script"
contents of d
-- AppleScript asks the script editor for `document 2`, and it
returns
-- document 2 of application "Script Editor"
contents of contents of d
-- AppleScript asks the script editor for `contents of document
2`, and it returns
-- the text content of the document
contents of document 2
-- AppleScript asks the script editor for `contents of document
2`, and it returns
-- the text content of the document
end tell
This "conflict" between the contents property and the contents of
operator can be confusing.
To solution in this situation (when you've got a specifier stored in
a variable) is to use the double contents of syntax:
set s to contents of contents of variableName
Jim
--
------------------------------------------------------------------
This message is sent to you because you are subscribed to
the mailing list <yojimbo-talk@barebones.com>.
To unsubscribe, send mail to: <[EMAIL PROTECTED]>
List archives: <http://www.listsearch.com/yojimbotalk.lasso>
Have a feature request, or not sure if the software's working
correctly? Please send mail to: <[EMAIL PROTECTED]>