• 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: Paul Berkowitz <email@hidden>
  • Date: Wed, 19 Nov 2003 10:32:08 -0800

On 11/19/03 9:06 AM, "David A. Cox" <email@hidden> wrote:

> I am stuck on something simple, and I don't know why I can't get my head
> around what is wrong.
>
> I want to set a variable to a command name in a script for itunes, and I
> can't seem to get the command to execute.
>
> This works:
>
> tell application "iTunes"
> play
> end tell
>
> This does not:
>
> set command to "play"
> tell application "iTunes"
> command
> end tell
>
> I have fiddled around with different syntax ways of saying the same thing,
> but I seem to fail each time. I am using the latest OS and iTunes. I am
> sure I am just missing something super basic, but I can't seem to see
> it....

1) In the first script, 'play' is not a string - it's not in quotes, it's an
application keyword defined by the application iTunes, and only definable in
its own tell block. In the second script, you're trying to use a variable
which is a string - "play" - not the same thing at all. Why do you want to
do this anyway?

2) You can't set a variable to an event (command) which doesn't have a
result ('play' does not have result - check the dictionary). You can only
set variables to values, not to commands (events). When you set a variable
to an event which does have a result, the event will be executed and the
variable set to the resulting value. In the iTunes Suite only 'add' and
'convert' have a result (a track).

3) It is possible to compile raw codes* outside the tell block, and set a
variable to that, but it still won't work for events.

Suppose you tell us what you're really trying to do, and why. Substituting a
variable for an event name is pointless in itself - what is it you're trying
to get around by doing this? There's probably a way to do what you really
want.

* You can find all application raw codes using either Script Debugger or
Smile. play is

<<event hookPlay>>

I'm using << and >> as placeholders because this mailing list has been
stupidly configured to defeat the proper communication of AppleScript
issues. The actual characters are the "double-angle quotations" made on US
keyboard by typing option-\ and shift-option-\ .

That will compile outside an iTunes tell block, but still won't execute if
you set a variable to it, because it's an event, not a value.



However



--
Paul Berkowitz
_______________________________________________
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.

  • Prev by Date: Re: set variable to a command?
  • Next by Date: Re: Getting label from a record (part 2)
  • Previous by thread: Re: set variable to a command?
  • Next by thread: Re: set variable to a command?
  • Index(es):
    • Date
    • Thread