Skip to content

Instantly share code, notes, and snippets.

@ivan-leschinsky
Last active September 22, 2021 16:10
Show Gist options
  • Save ivan-leschinsky/4d0ea719992582096186b34942d68e79 to your computer and use it in GitHub Desktop.
Save ivan-leschinsky/4d0ea719992582096186b34942d68e79 to your computer and use it in GitHub Desktop.
Applescript play/pause scripts for the VLC, iTunes, Spotify, Deezer
(*
-- When running each app separately
tell application "Deezer"
if it is running then
set old to (path to frontmost application as text)
tell application "Deezer"
reopen
activate
end tell
tell application "System Events" to key code 49
delay 1
activate application old
-- tell application "Deezer" to play
-- tell application "Deezer"
-- tell application "System Events" to key code 49
-- end tell
end if
end tell
tell application "VLC"
if it is running then
tell application "VLC"
playpause
end tell
end if
end tell
tell application "iTunes"
if it is running then
tell application "iTunes"
playpause
end tell
end if
end tell
*)
(*
-- save previous app and run it after the action
set previousRunningApp to (path to frontmost application as text)
-- activate and use needed app
activate application previousRunningApp
*)
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
on isAppLoaded(appName)
tell application "System Events" to set appList to every «class pcap» whose name is appName
return ((count of appList) > 0)
end isAppLoaded
if is_running("VLC") then
tell application "VLC"to play
else if is_running("Deezer") then
tell application "System Events"
tell process "Deezer"
click menu item 1 of menu 1 of menu bar item "Controls" of menu bar 1
end tell
end tell
else if is_running("Spotify") then
tell application "Spotify"to playpause
else if is_running("iTunes") then
tell application "iTunes" to playpause
else
tell application "iTunes"
reopen
activate
playpause
end tell
end if
-- another solution
if application "VLC" is running then
tell application id (id of application appName)
open location "http://google.com"
end tell
return "Running"
else
return "Not running"
end if
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment