Skip to content

Instantly share code, notes, and snippets.

@Coro365

Coro365/iTunes.sh

Last active Nov 16, 2019
Embed
What would you like to do?
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