Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Quick add currently-playing track to an iTunes playlist Apps
Oftentimes when I'm listening to music in my library, randomly or in the "recently added" list, I'll think to myself "wow -- that's a great love song, I need to add that to my 'lovesongs' playlist..." But I am too lazy (or busy) to switch to iTunes and drag it over. So I created an AppleScript that's triggered by a keyboard shortcut to add the currently-playing iTunes track to a playlist I specify.

Features:
  • Prompts you for the playlist name
  • Will create the playlist if it doesn't exist
  • Will not add the track if it's already on the designated playlist
  • Designed to be executed with a hotkey "trigger" event (keyboard shortcut) with Quicksilver or some other shortcut program. See how-to on adding keyboard hotkeys with Quicksilver
  • Unobtrusively shows the result with a growl message
When invoked with the hotkey, the script will prompt you for the playlist name in a pop-up dialog; type the playlist's name then click OK and you're done. Here's the script:
set currentApp to current application
tell currentApp
activate
set myList to the text returned of (display dialog "Enter playlist to add track to" default answer "")
end tell

--exit if they didn't enter anyting
if the myList is "" then return

--make sure itunes is installed
property okflag : false
tell application "Finder"
if (get name of every process) contains "iTunes" then 
 set okflag to true
end tell

if okflag then
set myMessage to ""
tell application "iTunes"
 set oldfi to fixed indexing
 set fixed indexing to true
 set thisTrack to (get location of current track)
 set dbid to (get database ID of current track)

 --see if the playlist exists
 if exists user playlist myList then
  --do nothing for now
 else
  make new user playlist with properties {name:myList}
 end if
 set currentList to playlist myList

 --see if the track exists on the playlist
 set currentIDs to {}
 try
  if exists (track 1 of currentList) then -- if there are some tracks - at least one -- get their ids
   copy (get database ID of every track of currentList) to currentIDs -- list
  end if
 on error errText number errnum
  if errText does not contain "Invalid index." then
   error errstr number errnum
  end if
 end try

 --add the track to playlist or show error
 if currentIDs does not contain dbid then -- if id not already present add the track
  add thisTrack to currentList
  set myMessage to " Track added to playlist " & myList
 else
  set myMessage to " Selected track already on playlist " & myList
 end if
 set fixed indexing to oldfi
end tell
end if

--show our output message
-- Check if Growl is running:
tell application "System Events"
set isRunning to 
 (count of 
  (every process whose name is "GrowlHelperApp")) > 0
end tell

--Only display growl notifications if Growl is running:
if isRunning = true then

tell application "GrowlHelperApp"
 -- Make a list of all notification types:
 set the allNotificationsList to 
  {"Notification 1", "Notification 2"}

 -- Make a list of the default enabled notifications:
 set the enabledNotificationsList to 
  {"Notification 1"}

 -- Register the script with Growl
 -- using either "icon of application"
 -- or "icon of file":
 register as application 
  "add_to_playlist" all notifications allNotificationsList 
  default notifications enabledNotificationsList 
  icon of application "Script Editor"

 -- Send a notification:
 notify with name "Notification 1" title "Track add output" description myMessage application name "add_to_playlist"
end tell
else
tell currentApp
 activate
 display dialog myMessage giving up after 1
end tell
end if
[robg adds: I haven't tested this one.]
    •    
  • Currently 1.83 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[8,903 views]  

Quick add currently-playing track to an iTunes playlist | 8 comments | Create New Account
Click here to return to the 'Quick add currently-playing track to an iTunes playlist' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Quick add currently-playing track to an iTunes playlist
Authored by: DougAdams on Jul 13, '09 07:54:59AM
Man, that "ok_flag" routine is clunky. How about:
on itunes_is_running()
	tell application "System Events" to return (exists process "iTunes")
end itunes_is_running

---
Doug's AppleScripts for iTunes
dougscripts.com

[ Reply to This | # ]

Quick add currently-playing track to an iTunes playlist
Authored by: midget2000x on Jul 13, '09 09:25:44AM

Noted. Thanks for the tip! It's probably completely unnecessary anyway, because it's highly unlikely that iTunes *doesn't* exist on any given mac.



[ Reply to This | # ]
Quick add currently-playing track to an iTunes playlist
Authored by: DougAdams on Jul 13, '09 10:05:48AM
...it's highly unlikely that iTunes *doesn't* exist on any given mac.
Er, that's not what the handler does. It reports if iTunes is running or not.

---
Doug's AppleScripts for iTunes
dougscripts.com

[ Reply to This | # ]

Quick add currently-playing track to an iTunes playlist
Authored by: midget2000x on Jul 13, '09 10:53:01AM

Whoops! you're right. My comment in the script is incorrect.



[ Reply to This | # ]
Quick add currently-playing track to an iTunes playlist
Authored by: boredzo on Jul 13, '09 08:14:04AM

Or:

  1. Press ⌘L.
  2. Right-click the track.
  3. Choose the playlist from "Add to Playlist".

Granted, it won't create a playlist, you can't hotkey it, and it doesn't post a Growl notification. But how quickly do you need to add something to a playlist, and do you really need a Growl notification for something you just did?



[ Reply to This | # ]
Quick add currently-playing track to an iTunes playlist
Authored by: asmeurer on Jul 13, '09 09:18:19AM
You can create a keyboard shortcut for the playlist, but you have to right click on the track first. See this hint.

And of course, you have to actually have to bring iTunes to the foreground first to do this.

[ Reply to This | # ]
Quick add currently-playing track to an iTunes playlist
Authored by: midget2000x on Jul 13, '09 09:28:15AM

Yeah, the idea is to not have to switch to iTunes to add the track. Also, the growl output isn't completely necessary, but personally I like some kind of notification that an action I took actually completed. It also shows you output results.



[ Reply to This | # ]
Quick add currently-playing track to an iTunes playlist
Authored by: jchris on Jul 13, '09 12:51:07PM

Good idea. However, did you try SizzlingKeys? You can do much more things using it. Cheers!



[ Reply to This | # ]