 |
 |
applescript works in editor, but not as app
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2001
Location: Cupertino, CA
Status:
Offline
|
|
i'm have a quick applescript that i wrote to play or pause itunes (yeah, it's dumb, but i want to use keyboard maestro to launch it so i can play/pause with a keystroke). it works when i hit "run" in the editor, but when i save it as either a compiled script or as an application, it doesn't work. anyone have any ideas? i'm running it on 10.1.3 if that matters. the script is below.
thanks,
kelly
tell application "iTunes"
if (player state as string = "playing") then
pause
else
play
end if
end tell
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Nov 2001
Location: Seattle, WA
Status:
Offline
|
|
[ 02-24-2002: Message edited by: DP Roberts ]
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Nov 2001
Location: Seattle, WA
Status:
Offline
|
|
Kelly, this works:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
tell application <font color = red><font color = red>"iTunes"</font></font>
if (<font color = blue>player state</font> = <font color = blue>playing</font>) then
pause
else
play
end if
end tell
</font>[/code]
But I don't have the answer to your question as to why it works as a script, and not an application. However, <font color = red>player state</font> returns a constant <font color = red>playing</font>. The saved application won't force the type to a string, although script editor seems to. Just keep it as a constant.
[ 02-24-2002: Message edited by: DP Roberts ]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2001
Location: Cupertino, CA
Status:
Offline
|
|
yay! thanks, that works! i always stumble around applescript and the syntax; knowing other programming languages seems to make my life harder.
i did find another solution, too. changing the if statement to:
i have a simple applescript that seems to work fine in Script Editor when run:
tell application "iTunes"
if (player state as string = "playing") then
pause
else
play
end if
end tell
but when i compile the script to run as an app, it fails. why? i entered some display dialogs of the "player state as string" var, and when run from Script Editor, it correctly appears as "playing" or "stopped". when run as a compiled app, they appear as "«constant ****kPSP»" and "«constant ****kPSS»", respectively. i've changed my script to:
if (player state as string = "playing" or (player state as string) contains "PSP") then
since when launched as an app, the script returns the constants "kPSP" for playing and "kPSS" for stopped. your solution is better, though. thanks again!
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Nov 2001
Location: Seattle, WA
Status:
Offline
|
|
Originally posted by kelly_hirano:
<STRONG>yay! thanks, that works! i always stumble around applescript and the syntax; knowing other programming languages seems to make my life harder. 
</STRONG>
I could pretend--in all this anonymity--to be some sort of expert, but I'm stumbling myself. Honestly, I was just lucky enough to stumble on the answer after you made me curious enough to start looking for one.
Personally, I like your solution too. In fact I think we found different answers the same way (looking at what the variable "player state" gets assigned)...but I never thought of your solution.
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> if (player state as string = <font color = red>"playing"</font> or (player state as string) contains <font color = red>"PSP"</font>) then
</font>[/code]
since when launched as an app, the script returns the constants "kPSP" for playing and "kPSS" for stopped. your solution is better, though. thanks again![/QB]
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
I stumbled on the same solution Kelly did (the 'kPSP' one) a while ago while working on a custom script for controlling iTunes from Snak and Ircle...I also submitted a bug to Apple about it, since really, playing as a string should be "playing"...though I think I may have misfiled it.
Thanks, DP, for the alternate solution as well!
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|