AppleScript iTunes question
Anyone know why this works,
tell application "iTunes"
playpause
end tell
But this does't?
set theTail to "playpause"
tell application "iTunes"
theTail
end tell
MacBook Air, OS X Mountain Lion (10.8.4)
Anyone know why this works,
tell application "iTunes"
playpause
end tell
But this does't?
set theTail to "playpause"
tell application "iTunes"
theTail
end tell
MacBook Air, OS X Mountain Lion (10.8.4)
playpause is an applescript command defined by itunes. theTail is a string variable as you've set it. It may be possible to set a variable to the command playpause and then invoke the command by calling the variable; I haven't tried, but I know that commands are technically application-defined handlers, and handlers can in normal cases be assigned to variables. But that line of thought is liable to provoke brain-freeze, so just take it as read that there's no easy way to use a string variable in place of an application defined keyword.
yes, but this works...
set theTail to "80's"
tell application "iTunes"
playplaylisttheTail
end tell
that's becuase playlist is an applescript object which has a 'name' property that's a string. basically your line 3 translates in applescript to tell itunes to play a playlist object whose name property is equal to the string "80's". see the difference?
Yes, but there has got to be a way to do my original post. Hopefully someone who knows will chime in!
I'm afraid you're going to have to explain what you're trying to do. I explained why what you actually did doesn't work, but I have no idea from your post what your intended goal is.
I'm trying to bring in one word actions for iTunes as a variable, and the have the script execute that action.
Play, pause, playpause, next, etc....
I suppose you could do some kind of hack with the run script command, but it sounds like you have things backward. Normally you would execute the proper commands from the results of a control statement (or if using Cocoa-AppleScript, an action handler connected to a button or menu) - what exactly are you trying to do?
Not really looking for a workaround....I know how to do what I want the long way....just was curious why this didn't work. I figured there was an extra line I could put in to make the string be a command....figured someone might know.....
Well, as twtwtw posted earlier, those are commands added by iTunes, and don't have any meaning outside of an iTunes application tell statement. You can try to break out the event codes, but that kind of defeats the purpose.
Application command needs to be compiled into Apple Event code by AppleScript compiler. You may employ "run script" command if you really need to compile source code at run time. Like this -
itunes_command("playpause")
on itunes_command(s)
run script "tell application \"iTunes\" to " & s
end tell_itunes_toRegards,
H
AppleScript iTunes question