Skip to content

Instantly share code, notes, and snippets.

@dreness
Created January 9, 2015 19:53
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 dreness/304fa170b65aece953c9 to your computer and use it in GitHub Desktop.
Save dreness/304fa170b65aece953c9 to your computer and use it in GitHub Desktop.
Tiny shell script that prints the current iTunes track info and remaining time; does not scroll.
#!/bin/bash
INTERVAL=$1
while true ; do
output=$(
osascript -- - <<'EOF'
tell app "iTunes"
try
set artist_track to artist of current track ¬
& " - " & name of current track
set track_end to finish of current track
set current_pos to player position
end try
end tell
try
artist_track
track_end
current_pos
if class of track_end is real and class of current_pos is real then
set remaining to (round (track_end - current_pos))
end if
if remaining >= 0 then
do shell script "echo " & quoted form of artist_track & ¬
" 🔊 " & "$(date -r " & remaining & " +%M:%S)"
end if
on error
--faile
end try
EOF
)
echo -en "\r\033[K${output}"
if [ "$INTERVAL" -eq "$INTERVAL" ] 2>/dev/null; then
sleep $INTERVAL
else
sleep 5
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment