Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > applescript works in editor, but not as app

applescript works in editor, but not as app
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Feb 22, 2002, 04:27 PM
 
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
Reply With Quote
Feb 24, 2002, 01:33 PM
 


[ 02-24-2002: Message edited by: DP Roberts ]
     
Junior Member
Join Date: Nov 2001
Location: Seattle, WA
Status: Offline
Reply With Quote
Feb 24, 2002, 01:37 PM
 
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
Reply With Quote
Feb 25, 2002, 07:19 PM
 
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
Reply With Quote
Feb 27, 2002, 09:37 PM
 
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
Reply With Quote
Feb 28, 2002, 07:51 AM
 
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];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2