Skip to content

Instantly share code, notes, and snippets.

@Zettt
Created November 8, 2012 11:31
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 Zettt/4038282 to your computer and use it in GitHub Desktop.
Save Zettt/4038282 to your computer and use it in GitHub Desktop.
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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment