Making a Proximity script that stores whether iTunes was playing or not when you leave the computer, and uses that state when you return. Here's the relevant code:
Code:
on entered_proximity()
tell application "System Events"
set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
set wasiTunesPlaying to ¬
(do shell script "defaults read nu.mine.alastor.ClickerScripts ClickiTunesWasPlaying") = "1"
if wasiTunesPlaying = true then
tell application "iTunes" to play
end if
end if
end entered_proximity
on left_proximity()
tell application "System Events"
set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
tell application "iTunes"
do shell script ¬
"defaults write nu.mine.alastor.ClickerScripts ClickiTunesWasPlaying -boolean " & ¬
(((player state as string) = "playing") as string)
end tell
tell application "iTunes" to pause
end if
end left_proximity
nu.mine.alastor.ClickerScripts ClickiTunesWasPlaying is always set to 0 when run through the left_proximity! The code works flawlessly when run in Script Editor.
I can't find an error in the code. It seems as if iTunes is paused by something else before my left_proximity code is executed. But I've made sure -- there are NO events assigned to "leaving the computer", nor is any other iTunes proximity script active!
I just can't figure it out! Can anyone help me?
ps. If you want to try the code, the above works just nicely, if you just copy it into a new Proximity Script and replace the default contents with it