Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.