Skip to content

Instantly share code, notes, and snippets.

@axiixc
Created May 5, 2009 01:07
Show Gist options
  • Save axiixc/106775 to your computer and use it in GitHub Desktop.
Save axiixc/106775 to your computer and use it in GitHub Desktop.
-- iTunes Info by James Savage [ AXIIXC : axiixc.com ]
-- Best used with GeekTool
if appIsRunning("iTunes") then
tell application "iTunes"
if player state is stopped then
set output to ".: No Track Selected :."
else
-- Player State
if player state is playing then
set state to "Playing"
else
set state to "Paused"
end if
-- Basic Info
set song to name of current track
set song_artist to artist of current track
set song_album to album of current track
-- Rating
if true then -- set to false to disable
set has_stars to ((rating of current track) / 20) as integer
set not_stars to 5 - has_stars
set song_rating to ""
repeat has_stars times
set song_rating to song_rating & "#"
end repeat
repeat not_stars times
set song_rating to song_rating & "-"
end repeat
else
set song_rating to ""
end if
set song_info to state & " : " & song & " - " & song_album & " (" & song_artist & ") " & song_rating
-- Times (time converson taken from Graham Nelson's http://www.gnelson.demon.co.uk/applescript/)
set no_seconds_played to the player position as number
set no_minutes_played to no_seconds_played div 60
set no_seconds_played to no_seconds_played mod 60
if no_seconds_played < 10 then
set seconds_text_played to "0" & (no_seconds_played as string)
else
set seconds_text_played to no_seconds_played as string
end if
set no_seconds_left to the (duration of current track) - player position as integer
set no_minutes_left to no_seconds_left div 60
set no_seconds_left to no_seconds_left mod 60
if no_seconds_left < 10 then
set seconds_text_left to "0" & (no_seconds_left as string)
else
set seconds_text_left to no_seconds_left as string
end if
set time_played to (no_minutes_played as string) & ":" & seconds_text_played
set time_total to time of current track
set time_left to (no_minutes_left as string) & ":" & seconds_text_left
set time_info to "[" & time_played & "[" & time_total & "]" & time_left & "]"
-- Playbar
set the_length to (length of song_info) - (length of time_info) - 3
set has_played to ((player position / (duration of current track) * the_length) as integer)
set not_played to the_length - has_played
set cap to "["
set end_cap to ""
repeat has_played times
set cap to cap & "="
end repeat
if has_played is 100 then
set cap to cap & "="
else
set cap to cap & ">"
end if
repeat not_played times
set end_cap to end_cap & " "
end repeat
set end_cap to end_cap & "]"
-- Putting it all together
-- There is an extra space appended here. It helps it line up better for me
-- but you may want to remove it
set output to song_info & "
" & cap & end_cap & time_info & ""
end if
end tell
else
set output to ".: iTunes Not Running :."
end if
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment