--iTunesSU
-- This is just PlayPause Script saved in App form
-- So I can give it an Icon and Drag it into the Dock
-- BP July 2015
set isrunning to 0
tell application "iTunes"
if it is running then
set isrunning to 1
playpause
end if
end tell
if isrunning is equal to 1 then return
-- It's not running, want to start it up, and kill any warning dialog
tell application "iTunes"
activate -- this'll start iTunes if it's not already up
-- try
-- set frontmost to true
-- end try
end tell
delay 0.2 -- iTunes needs a little time to stabilize
tell application "System Events"
try
set z to name of front window of application process "iTunes"
-- This returns "" if it's a warning dialog
-- "iTunes" if it's the main music window or mini player
-- Track and album name if it's cover view up front
-- error if no iTunes windows are open
-- "General Preferences" if Prefs is open
-- Album name if "Get info" is open
-- "Equalizer" if equalizer window is open
on error
set z to "Bubblepuppy"
end try
if z is equal to "" then
--set z to name of (static text of window 1 of application process "iTunes") as text -- might eventually be useful
delay 0.2 -- iTunes needs a little time to stabilize
keystroke "
"
end if
end tell
-- iTunes doesn't remember what's playing between starts, so the following lines will just start playing whatever happens to come up first
-- always the same, or shuffled if shuffle is set.
--delay 0.1
--tell application "iTunes" to playpause
return