Skip to content

Instantly share code, notes, and snippets.

@Coro365
Last active November 16, 2019 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coro365/1fb75d74c68a8a012c9f2a0acfeac74d to your computer and use it in GitHub Desktop.
Save Coro365/1fb75d74c68a8a012c9f2a0acfeac74d to your computer and use it in GitHub Desktop.
This script iTunes(Music.app) play, pause, next track, back track and return state.
#!/bin/sh
# @(#) This script Music.app play, pause, next track, back track and return state.
# @(#) Support macOS Catalina version.20191116
if [ -z "$1" ]; then
echo "Argument is missing!"
exit 1
elif [ "$1" == "play" ]; then
music_run=`osascript -e 'application "Music" is running'`
if [ "$music_run" == "false" ]; then
osascript -e 'tell application "Music" to activate'
fi
osascript -e 'tell application "Music" to play'
elif [ "$1" == "pause" ]; then
music_run=`osascript -e 'application "Music" is running'`
if [ "$music_run" == "true" ]; then
osascript -e 'tell application "Music" to pause'
fi
elif [ "$1" == "next" ]; then
osascript -e 'tell application "Music" to next track'
elif [ "$1" == "back" ]; then
osascript -e 'tell application "Music" to back track'
elif [ "$1" == "status" ]; then
osascript ./iTunes_status.scpt
else
echo "Invalid argument!"
exit 1
fi
if application "Music" is running then
tell application "Music"
set a to player position as text
delay 1
set b to player position as text
if a = b then
--log "status:pause"
return 0
else
--log "status:play"
return 1
end if
end tell
else
--log "Music.app not working"
return 0
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment