Re: objectSpecifier
Re: objectSpecifier
- Subject: Re: objectSpecifier
- From: Jesse Grosjean <email@hidden>
- Date: Thu, 15 Jan 2004 08:33:28 -0500
Don,
Thank's very much for your reply. The good news is that I've got things
working and am on my way forward again. I've reposted a working version
of the ScriptTest for anyone who's interesting. URL is at end of
message ... you must read my questions first. ha ha ha!
[1] There's a new demo project, ToManyDemo, on my .Mac homepage
http://homepage.mac.com/donbriggs
I actually tried to look at this before posting to the list, but it
leads me to a file not found .mac page.
[2] Consider changing MyDocument's root instance of Node from being an
attribute to being a to-one relationship.
Are to-one relationships any different then attributes? I'd been lead
to believe that to-one relationships should be avoided by looking at
some posts in the cocoa-dev list archives. Also I don't see any way to
specify to-one relationships in the .sdef format. I was thinking that
they were no longer really used.
[3] Consider using the same Apple Event Code 'STnd' for
the declaration of Node (as you have it);
Node's to-many relationship to subnodes (as you have it); and
MyDocument's to-one to "root" (you have it as an attribute, with
code 'STrt')
I don't see a need for the extra code 'STrt' .
It seems probably innocuous, though.
If I change the root code to 'STnd' then it changes my applescript code
that used to look like this:
tell root
make new row at end of rows
end tell
to this:
tell row
make new row at end of rows
end tell
So I lose the "root" term. It also
However, this answer provides NO insight into an implementation of
-objectSpecifier.
The sample code provides no object specifier method.
It just works.
Without an objectSpecifier can your applescript do something like this?
make new containee at end of containees
set x to last containee
set name of x to "this is my new name"
From what I can tell it's necessary to implement the objectSpecifier
method if you want applescript to be able to "hold" a reference to one
of your application objects in a variable. (x in this case) At least
that's the mental model that I've built for myself, if I'm incorrect
someone please correct me.
Ok now a few questions. It seems like the common practice for object
specifiers is to return relative specifiers that might look something
like this:
row 1 of document "Untitled" of application "ScriptTest"
A side effect of this is that this applescript will do something a bit
unexpected (at least to those who don't use functional languages
daily):
make new row at end of rows
set x to last row
make new row at end of rows
set the name of x to "this is x"
In my objective-c based mind I would have expected the first row to
have it's name changed to "this is x" since x "was assigned" the last
row when only one row was created. But of course with relative object
specifiers x really is always referring to the "last row". So in this
case it's really the last of the two rows that get's it's name set to
"x".
Is this feature something that is desirable and that applescripters are
used to? As an alternative I could return a uniqueID specifier (all my
rows have non-mutable unique id's) that's evaluated directly by my
document container. I think this would make things a bit (probably
doesn't really matter though) faster since it's very fast for my
application to find a row by uniqueID. And it would arguably make
applescript code easier to write since it would make the set command
behave more like a c style assignment. But then relative references
have their own power... so what do people recommend?
Last question. Right now my ScriptTest example is working great:
http://www.hogbay.com/software/ScriptTestExample.zip
But I'd like to alias the "row/rows" terms to "subrow/subrows". My goal
is to be able to write this applescript.
tell application "ScriptTest"
tell first document
make new row at end of rows -- case 1
make new subrow at end of rows -- case 2
make new row at end of subrows -- case 3
make new subrow at end of subrows -- case 4
end tell
end tell
So all those terms should do the exact same thing. I've got case 1 and
2 working by adding
<class name="subrow" inherits="row" code="NBsr">
<cocoa class="Node"/>
</class>
to my ScriptTest's sdef file. But I'm not sure how to get cases 3 and 4
working. Suggestions?
Thanks for your time. I hope by posting these project others can get up
to speed a bit faster that it's taking me. I'm amazed at how easy it is
to integrate applescript once things are set up correctly, but I'm
amazed at how hard it is to get to this initial state. I think just a
few more good examples would greatly increase the use of applescript in
cocoa applications.
Jesse
_______________________________________________
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.