Re: Coerce from string to application command
Re: Coerce from string to application command
- Subject: Re: Coerce from string to application command
- From: Doug Korns <email@hidden>
- Date: Thu, 9 Nov 2000 13:30:21 -0800
>
I tried to find this in the archives, to no avail. Is it possible to
>
translate a string into an application command? For example, without using
>
else ifs...
>
>
set doAction to "delete"
>
tell app "Finder" to doAction file "foo"
>
This cannot be done as straight forward as you might wish, in your
example.
AppleScript needs to be able to resolve a specific action, at compile
time, for your second statement and the verb doAction cannot be
determined at compile time.
You could construct something more dynamic using 'run script' along these
lines:
--
set doAction to "delete"
set TheScript to ,
"tell application \"Finder\" to " & doAction & " file \"foo\" "
run script TheScript
--
This allows you to delay until runtime the computed action on the file
and to dynamically create the desired (compilable) AppleScript statement
to perform the computed action on the file. You still use a series if
if-then-else statementst to set the doAction variable, leading up the
dynamically constructed statement and it's invocation.
My suspicion is that this method, operating on a lot of files, will be
slower than a series of if-then-else statemnts with the specific actions
compiled in. The reason being that you will be repeatedly invoking the
AppleScript compiler/run time mechanism for each file action, rather than
just sending a precompiled AppleEvent.
HTH,
Doug Korns