Skip to content

Instantly share code, notes, and snippets.

@hiway
Last active December 10, 2015 11:28
Show Gist options
  • Save hiway/4427513 to your computer and use it in GitHub Desktop.
Save hiway/4427513 to your computer and use it in GitHub Desktop.
Script to print currently playing track from iTunes on MacOSX — I use this to tweet out my favorite songs. (works on Snow Leopard) Bonus script: youtube_current_song.py will give you a youtube search URL for current song - again useful when tweeting. It also prints exception to stdout, useful for debugging with automation tools like TextExpander.
import appscript
itunes = appscript.app('itunes')
if itunes.isrunning():
track = itunes.current_track()
status = "#music %s by %s" %(track.name(), track.artist())
album = track.album()
if album:
status += " from %s" %(album)
print status
appscript==1.0.1
import appscript
import urllib
itunes = appscript.app('itunes')
try:
if itunes.isrunning():
track = itunes.current_track()
status = "www.youtube.com/results?"
query = track.name() + " " + track.artist()
status = status + urllib.urlencode({"search_query":query})
print status,
except Exception, e:
import traceback, sys
traceback.print_exc(file=sys.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment