Re: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
Re: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
- Subject: Re: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
- From: Walter Ian Kaye <email@hidden>
- Date: Fri, 9 Apr 2004 23:19:00 -0700
At 06:15p -0700 04/09/2004, Michael Terry didst inscribe upon an
electronic papyrus:
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"
I have *never* used 'contents' in that way. Actually, the only time I
ever used contents was for UI objects such as text windows. Never
used it with lists; never needed to. The following works just fine,
exactly the same as in Perl:
AS:
set {a, b} to {"hello", "there"}
{a, b}
--> {"hello", "there"}
Perl:
($a, $b) = ("hello", "there");
I've been using that technique in AS for years.
But as you say, you have to hard code the variable names. There is,
of course, the 'run script' command, although compilation in AS is
not as fast as in Perl.
(I don't know how you'd do a 'whose clause' in Perl anyway.)
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.
So, have you looked at the table suite? Or at Excel's "range"
references? Or at FileMaker's repeating fields?
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.
Yup. So if you can build that "collection" yourself, such as a range
reference, you can then assign an array to it.
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.
Thus the existence of 'a reference to' so that you can ask for a
reference if you need it.
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.
The alternative would be to do like is often done with Excel:
1. get the boundaries of the range you want to affect
2. build a range reference based on those boundaries
3. assign an array to that range
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.
Suggest the above alternative, assuming it's not already in there.
-boo
_______________________________________________
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.