Re: set variable to a command?
Re: set variable to a command?
- Subject: Re: set variable to a command?
- From: kai <email@hidden>
- Date: Fri, 21 Nov 2003 03:59:34 +0000
on Thu, 20 Nov 2003 13:51:37 -0500, Arthur Knapp wrote:
>
>> From: Michelle Steiner <email@hidden>
>
> Subject: Re: set variable to a command?
>
> Date: Thu, 20 Nov 2003 09:08:57 -0700
>
>
>> On Nov 20, 2003, at 8:20 AM, Arthur Knapp wrote:
>
>
>> Does iTunes have its own "run script" command? It is hard to see how
>
>> the terminology gets mapped to the right iTunes's AppleEvent inside of
>
>> "run script."
>
>
> "run script" is an Applescript command. In the case at hand
>
> run script command
>
> equates to
>
> run script "play"
>
>
Right, and that's what I don't understand. My experience is that "run
>
script" compiles within its own "context," meaning that:
>
>
run script "play"
>
>
should be exactly the same as if you typed the word "play" all by
>
itself into a new script editor window and then clicked the run button.
>
Generally, when a script compiles, it figures out terminology based on
>
the current tell-statement:
>
>
tell application "iTunes" --> compiler searches iTunes's terminology... play
>
--> ... for "play" and finds <<event hookPlay>> as mentioned by Paul B.
Apologies for the late response. I had the temerity to leave my post. 8-O
My understanding is that 'run script' is not quite the same as running a
script object. Since the former compiles at runtime, it can apparently run
within the context of a tell block. The latter, which is obviously compiled
at the same time as the main script, wouldn't have this ability.
For example, if the word 'disk' is entered in a Script Editor window, and
the run button clicked, the result is an error. The problem can obviously be
resolved within a Finder tell block, because 'disk' is recognised as a
Finder object. A script object would also behave in a similar way.
(Apologies for the rather tedious examples):
=========
disk --> The variable disk is not defined.
---------
tell application "Finder" to disk --> disk
=========
script s
disk
end script
run s --> The variable disk is not defined.
---------
script s
disk
end script
tell application "Finder" to run s --> The variable disk is not defined.
---------
script s
tell application "Finder" to disk
end script
run s --> disk
---------
script s
using terms from application "Finder"
disk
end using terms from
end script
run s --> disk
=========
So, for any of the above examples to work, a reference to the Finder has to
be made at compile time.
My use of 'run script' was based on the assumption that the target script is
both compiled and run at runtime - therefore allowing it to work within a
current application tell block.
I suppose a more conventional way would be to run an entire script,
including the tell block, within quotes:
---------
run script "tell application \"Finder\" to disk" --> disk
---------
...but since 'run script' apparently compiles the target script within the
context of the tell block - and *then* runs it, this form also works:
---------
tell application "Finder" to run script "disk"
---------
The added benefit is that, OMM at least, the latter version runs some 20%+
faster (presumably because there's less to compile at runtime - but now I'm
*really* guessing). ;-)
---
kai
_______________________________________________
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.