Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Help Expected end of line, etc. but found end of script.

here is the sctipt ive tried to write, its not finished so some of the things my seem a bit weird at the moment but here it is as it stands


global okflag

set okflag to false

set front_app to (path tofrontmost applicationasUnicode text)


-- check if iTunes is running

tell application "System Events"

if process "iTunes" exists then

set okflag to true--iTunes is running

end if

end tell


if okflag is true then


set Timer to ""


display dialog "Sleep Time (Minutes)" default answerTimerbuttons {"Cancel", "OK"} default button 2

set Timer to text returned of the result


delay Timer * 60


tell application "iTunes"

set currentVolume to the sound volume

if (player state is playing) then

repeat

--Fade down

repeat with i from currentVolume to 0 by -1

set the sound volume to i

delay 1

end repeat

pause

--Restore original volume

set the sound volume to currentVolume

exit repeat

end repeat


if okflag is false then


display dialog "iTunes not playing" buttons {"OK"} default button 1 with icon stop


end if

end


it doesnt seem to work after the tell "iTunes part i copied and pasted from another applescript

(the purple text)

MacBook Air, Mac OS X (10.7.1)

Posted on Dec 14, 2012 5:35 PM

Reply
Question marked as Best reply

Posted on Dec 14, 2012 8:00 PM

Each if...then and tell statement containing multiple statements needs to be closed with an end if and end tell, respectively. It looks like something got mangled when pasting in the other script - I'm guessing it should be something like:


globalokflag

setokflagtofalse

setfront_appto (path tofrontmost applicationasUnicode text)


-- check if iTunes is running

tellapplication"System Events"


ifprocess"iTunes"existsthen

setokflagtotrue--iTunes is running


endif

endtell


ifokflagistruethen



setTimerto""


display dialog"Sleep Time (Minutes)"default answerTimerbuttons {"Cancel", "OK"} default button2


setTimertotext returnedoftheresult


delay Timer * 60



tellapplication"iTunes"

setcurrentVolumetothesound volume

if (player stateisplaying) thenrepeat

--Fade down

repeatwithifromcurrentVolumeto0by-1

setthesound volumetoi

delay 1

endrepeat

pause

--Restore original volume

setthesound volumetocurrentVolume

exitrepeat

endrepeat


endtell


else


display dialog"iTunes not playing"buttons {"OK"} default button1with iconstop

endif

2 replies
Question marked as Best reply

Dec 14, 2012 8:00 PM in response to alex149

Each if...then and tell statement containing multiple statements needs to be closed with an end if and end tell, respectively. It looks like something got mangled when pasting in the other script - I'm guessing it should be something like:


globalokflag

setokflagtofalse

setfront_appto (path tofrontmost applicationasUnicode text)


-- check if iTunes is running

tellapplication"System Events"


ifprocess"iTunes"existsthen

setokflagtotrue--iTunes is running


endif

endtell


ifokflagistruethen



setTimerto""


display dialog"Sleep Time (Minutes)"default answerTimerbuttons {"Cancel", "OK"} default button2


setTimertotext returnedoftheresult


delay Timer * 60



tellapplication"iTunes"

setcurrentVolumetothesound volume

if (player stateisplaying) thenrepeat

--Fade down

repeatwithifromcurrentVolumeto0by-1

setthesound volumetoi

delay 1

endrepeat

pause

--Restore original volume

setthesound volumetocurrentVolume

exitrepeat

endrepeat


endtell


else


display dialog"iTunes not playing"buttons {"OK"} default button1with iconstop

endif

Feb 3, 2013 7:06 AM in response to red_menace

cheers for this, id completely forgotten about this thread, i found a work around for it by just writing my own script for it, that and a few modifications:


global okflag

set okflag to false

set front_app to (path tofrontmost applicationasUnicode text)


-- check if iTunes is running

tell application "System Events"

if process "iTunes" exists then

set okflag to true--iTunes is running

end if

end tell


if okflag is true then

set CV to output volume of (get volume settings)

tell application "iTunes"

set currentVolume to the sound volume

if (player state is playing) then

repeat


--Fade down

repeat with i from currentVolume to 0 by -1

set the sound volume to i

delay 5.0E-4

end repeat


pause


--Restore original volume

set the sound volume to currentVolume

exit repeat

end repeat

else

set the sound volume to 0


play

repeat with j from 0 to currentVolume by 1

set the sound volume to j

delay 1.0E-4 * (CV)

end repeat

end if

end tell

tell applicationfront_app


activate

end tell

end if

Help Expected end of line, etc. but found end of script.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.