• 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: set variable to a command?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set variable to a command?


  • Subject: Re: set variable to a command?
  • From: Christopher Nebel <email@hidden>
  • Date: Thu, 20 Nov 2003 22:31:59 -0800

On Nov 20, 2003, at 10:51 AM, Arthur Knapp wrote:

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.

kai was pretty close. It doesn't exactly have to do with the enclosing "tell" block, but rather with the application the event was sent to. These are mostly, but not quite, the same thing. The reason this works has to do with how scripting additions are executed and an only occasionally-exploited feature of AppleScript. The net effect is as if the command string is surrounded by a "tell" block for the same application as the enclosing tell block.

First, if you tell an application to do any scripting addition, the addition is executed inside that application. (I briefly attempted to change this early in Mac OS X, but too many people relied on it, especially for UI.) Second, AppleScript treats the application executing a script as sort of an extension of AppleScript itself: its terminology is available when compiling, and if a script doesn't know how to handle a self-directed command (i.e., one without a tell block), it's passed to the executing application.

Put these two together: you tell iTunes to run script "play": iTunes creates its own AppleScript context, compiles the script -- which compiles correctly, because it sees iTunes's terminology -- and executes it, which also works because the "play" command is eventually handed to iTunes itself. This is the same principle that lets you write, say, FileMaker scripts that don't have a 'tell app "FileMaker"' block in them, because they're executing inside FileMaker.


--Chris Nebel
AppleScript Engineering
_______________________________________________
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.

References: 
 >Re: set variable to a command? (From: Arthur Knapp <email@hidden>)

  • Prev by Date: Re: iDisk access, WebDAV tools
  • Next by Date: Re: Script Editor self starting
  • Previous by thread: Re: set variable to a command?
  • Next by thread: Re: set variable to a command?
  • Index(es):
    • Date
    • Thread