(2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
(2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
- Subject: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
- From: Michael Terry <email@hidden>
- Date: Fri, 9 Apr 2004 18:15:26 -0700
(...continued...)
Not that I thought it would work, but I thought maybe I would suggest
it to my favorite application developers. The 'a reference to' operator
is one of the ways I mentioned a minute ago where you can access an
lvalue indirectly. But it turns out references in lists don't work the
way I'd hoped. I'll illustrate with variables as lvalues for
simplicity, but the principle's the same for property object
specifiers:
set x to 3
set y to 4
set a to a reference to x
set b to a reference to y
set contents of {a, b} to {"hello", "there"}
--> Can't set contents of {x, y} to {"hello", "there"}.
I don't know why that shouldn't work when you can get the contents of
each reference in a list of references, like so:
get contents of {a, b}
--> {3, 4}
and you can set an lvalue through a reference, example 1:
set a's contents to 7
x
--> 7
and, example 2:
set q to a reference to name of first file of item f of application
"Finder"
set q's contents to "hello there"
--> "hello there"
But none of the foregoing even touches on the bigger problem, the
second drawback to the original code, which I repeat as a reminder:
tell application "Finder"
set {name of first file of folder 1 of f, name of first file of folder
2 of f} to {"something", "else"}
end tell
See, separate Apple events are required for each property you assign
to. You can see that in the event log that's recorded when you run it:
tell application "Finder"
set name of file 1 of folder 1 of alias "Kinko's HD:Temporary Items:"
to "something"
"something"
set name of file 1 of folder 2 of alias "Kinko's HD:Temporary Items:"
to "else"
"else"
end tell
Two Apple events--that's what one would expect, but I wanted to
emphasize that even though you can set multiple unique properties in a
single line, it's not more efficient.
Could an application developer override 'set' so that it handled all of
the assignments at once? Would this be prohibitively hard? Is there
some way I don't know about to assign different values to properties of
multiple application objects at once?
Here's specifically why I want to know right now. I script OmniOutliner
a lot. OmniOutliner has columns, so it can be a bit like a spreadsheet.
With AS's wonderful reference forms, and OO's good support, I can
extract complex sets of data from my outlines, whole tables at a time
for instance. Even that belittles AS's querying powers, because it
might imply that the cells are contiguous, but that need not be the
case at all. Anyway, the point is, that's only half the battle. We OO
users need a similarly powerful, flexible, and fast way to put data
back in. Is there a way, using standard AppleScript commands, that OO
can do this?
The best solution of course would be one where I can use it now, if I
only knew the right syntax. Before reading Technote 2106, I wouldn't
have thought it possible, but now I realize that I didn't understand at
all what could be done with reference forms, so maybe I don't know
something here, either.
If my understanding isn't lacking, is there a general, elegant AS model
that OO could easily follow, maybe with a little tweak? Can
applications support this for instance:
tell application "Finder"
set name of first file of folders 1 thru 2 of f to {"hello", "there"}
end tell
That seems like the best way to do it to me. Is it dumb for some
reason? Would it be bad to extend 'set' this way? If so, is there a
suggested command name to do this sort of thing?
Here's an example using OO, which sets the value of every cell in a
column to an empty string:
tell application "OmniOutliner" to tell front document
set value of cell 2 of every row to ""
end tell
Notice here another method of accessing lvalues indirectly. When the
'value of cell 2 of every row' object specifier evaluates, it gets a
collections of lvalues somewhere internally in OO so that 'set' can
then set them all to an empty string. What I've never seen is an
application return property references for any command, say for example
'get'. If an application ever needs to return the result of a property
object specifier, it always returns its contents, often a simple
AppleScript type. Of course, even if an application returned property
object specifiers, that wouldn't solve the problem of efficiency I
mentioned before. So, in a nutshell, I want to be able to do this:
tell app "OmniOutliner" to tell front document
set value of cells 2 thru 3 of every row to {{"hello", 1}, {"what",
2}, ...}
end
or find a nice alternative. Omni's going to be releasing a new version
of Outliner soon, and they've made public that they're spending
considerable effort on the script support; there may never be a better
chance to influence its direction in a positive way. I'd like to be
able to suggest some things that will make scripting OO a pleasure a
few months from now.
Mike
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.