• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Coerce from string to application command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coerce from string to application command


  • Subject: Re: Coerce from string to application command
  • From: Jed Verity <email@hidden>
  • Date: Thu, 09 Nov 2000 13:49:25 -0800

Actually, Doug, that's just about perfect. I'm writing a very simple
application for the purpose of training my staff on the fundamentals of
AppleScript. They choose the application they want to control, the objects
involved, and what action to perform (on a per application basis). For
example, the application can create a test folder for them and move it to
the trash, or make an alias out of it, etc. depending on their wim (it then
displays the code -- particularly helpful for applications that aren't
recordable).

As you might imagine, generating else if structures for both nouns and verbs
is tedious at best. I think your solution might be just right. Thanks a
million.

Jed

On the threshold of genius, Doug Korns wrote:

>> 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
>
>


~)~)~)~)~)~)~)~)~)~)~)~)~)
Jed Verity


References: 
 >Re: Coerce from string to application command (From: Doug Korns <email@hidden>)

  • Prev by Date: Re: Coerce from string to application command
  • Next by Date: Question about submodules
  • Previous by thread: Re: Coerce from string to application command
  • Next by thread: List Archives now available
  • Index(es):
    • Date
    • Thread