Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AppleScript that gets currently playing track with title and name and whatnot and returns it only if iTunes is running. Useful for TextExpander snippets. (Include in optional section)
tell application "System Events"
if not (exists process "iTunes") then return
end tell
tell application "iTunes"
tell playlist "Rating = 5"
set trackCount to count of tracks
set randomTrackNumber to random number from 1 to trackCount
set trackTitle to name of track randomTrackNumber
set trackArtist to artist of track randomTrackNumber
set trackAlbum to album of track randomTrackNumber
end tell
end tell
return "#nowplaying: " & trackTitle & " by " & trackArtist & " from " & trackAlbum
tell application "System Events" if not (exists process "iTunes") then returnend telltell application "iTunes" tell playlist "Rating = 5" set trackCount to count of tracks set randomTrackNumber to random number from 1 to trackCount set trackTitle to name of track randomTrackNumber set trackArtist to artist of track randomTrackNumber set trackAlbum to album of track randomTrackNumber end tellend tellreturn "#nowplaying: " & trackTitle & " by " & trackArtist & " from " & trackAlbum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment