Skip navigation
This discussion is archived

Make smart playlists in iTunes?

1609 Views 10 Replies Latest reply: Jul 20, 2009 2:43 AM by dw32 RSS
dw32 Calculating status...
Currently Being Moderated
Jul 16, 2009 6:30 AM
Is it possible to do this? I have a pile of unsmart PLs that I want to convert to smart ones. I've got a scpt going that basically does the job, but although I say

make user playlist with properties {smart: true, name:PLname}

they always come out unsmart.

I note that the iTunes dictionary says smart is r/o, but surely for a new PL I'm just making, I can say smart:true ?
Mac OS X (10.4.9)
  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Jul 16, 2009 9:13 AM (in response to dw32)
    Maybe it's a new bug. Anyway, the script below uses [GUI Scripting|http://www.macosxautomation.com/applescript/uiscripting/index.html] to make a new smart playlist in iTunes (the Accessibility Frameworks must be enabled by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane):

    --BEGINNING OF SCRIPT
    tell application "iTunes" to activate
    tell application "System Events" to tell process "iTunes"
    keystroke "n" using {option down, command down} -- New Smart Playlist…
    keystroke return & return -- click the "OK" button, then the "Yes" button
    delay 0.5
    keystroke "New smart playlist" & return -- to rename the playlist
    end tell
    --END OF SCRIPT

    To build a rule from within the script, just replace the line “keystroke return & return" with the following tell block (changing the text strings to fit your needs):

    --BEGINNING OF REPLACEMENT LINES
    tell scroll area 1 of group 1 of window 1
    click pop up button 2
    click menu item "Composer" of menu 1 of pop up button 2
    delay 0.5
    click pop up button 1
    click menu item "is" of menu 1 of pop up button 1
    keystroke "Beethoven" & return
    end tell
    --END OF REPLACEMENT LINES

    Good luck.
    15-inch MacBook Pro 2.53 GHz, Mac OS X (10.5.7), AirPort Extreme
  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Jul 16, 2009 1:24 PM (in response to dw32)
    It was my pleasure.

    I must add that the *tell process "iTunes"* statement is necessary only with the replacement lines, and not when using just keystroke statements.

    Message was edited by: Pierre L.
    15-inch MacBook Pro 2.53 GHz, Mac OS X (10.5.7), AirPort Extreme
  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Jul 17, 2009 5:46 AM (in response to dw32)
    Did you try the script with longer delays, for example 1 sec. instead of 0.5 sec.?
    15-inch MacBook Pro 2.53 GHz, Mac OS X (10.5.7), AirPort Extreme
  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Jul 17, 2009 7:21 AM (in response to Pierre L.)
    All I can say is that the script seems to work OK on my computer, except when the iTunes window isn't already open. So I first added a few lines to the beginning of the script to handle that situation. Most importantly for you, I also added five 1 sec. delays, in order that you can check if the script works properly, though very slowly, with all of them present. If so, you could then try to remove them one by one, or choose shorter delays for some of them, until you find the best solution. I hope it can help.

    tell application "iTunes" to activate
    tell application "System Events" to tell process "iTunes"
    set menuItem to menu item "iTunes" of menu 1 of menu bar item "Window" of menu bar 1
    if value of attribute "AXMenuItemMarkChar" of menuItem is "" then
    keystroke "1" using {option down, command down} -- open the iTunes window
    delay 1 -- for testing
    end if
    keystroke "n" using {option down, command down} -- New Smart Playlist…
    tell scroll area 1 of group 1 of window 1
    delay 1 -- for testing
    click pop up button 2
    delay 1 -- for testing
    click menu item "Composer" of menu 1 of pop up button 2
    delay 1
    click pop up button 1
    delay 1 -- for testing
    click menu item "is" of menu 1 of pop up button 1
    delay 1 -- for testing
    keystroke "Beethoven" & return
    end tell
    delay 1
    keystroke "New smart playlist" & return -- to rename the playlist
    end tell

    My experience is that GUI scripting works well once adapted to the computer your are using.
    15-inch MacBook Pro 2.53 GHz, Mac OS X (10.5.7), AirPort Extreme
  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Jul 17, 2009 10:01 AM (in response to Pierre L.)
    Wonderful! Thanks for the feedback.
    15-inch MacBook Pro 2.53 GHz, Mac OS X (10.5.7), AirPort Extreme

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.