Created
January 9, 2015 19:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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