سؤال

I keep live update turned off on most of my smart playlists because changing anything, such as ratings, for a currently playing song could cause the song to disappear from the playlist if it no longer meets the smart playlist's criteria. The song stops playing and the playlist grinds to a halt. So far, the easiest solution has been to have an Applescript run automatically in the middle of the night to quit iTunes and then launch it again, thus forcing all of my smart playlists to update. This works. It's also easy enough to right click on a smart playlist and select "Update Smart Playlist." But what I'd rather do is use an Applescript to refresh all of my smart playlists and assign it a hotkey (using BetterTouchTool).

Is it possible to use Applescript to make iTunes smart playlists update?

هل كانت مفيدة؟

المحلول 2

Credit here goes to the answer above, by fartheraway. I just thought it could be helpful to post the full answer in case anyone does a search for something like this and finds my question. Here's the solution I ended up going with. Save this as an applescript and then assign it a hotkey using BetterTouchTool. This script will update the currently playing smart playlist. And if iTunes isn't the frontmost app, this script will switch to iTunes, update the playlist, and then take you back to app you were using (command+tab). This works for me! Thanks again to fartheraway for his help, above.

tell application "System Events"
    set frontmostApp to name of application processes whose frontmost is true
end tell

tell application "System Events" to tell application process "iTunes"
    set frontmost to true
    tell application "iTunes"
        try
            reveal current track
        end try
    end tell
    tell menu item "Edit Smart Playlist" of menu "File" of menu bar 1 to perform action "AXPress"
    tell button "OK" of window 1 to perform action "AXPress"
    end tell

if frontmostApp is not {"iTunes"} then
    tell application "System Events"
        key down command
        keystroke tab
        key code 123
        repeat while (exists list 2 of process "Dock")
            delay 0.1
        end repeat
        key up command
    end tell
end if

نصائح أخرى

Update Smart Playlist entry only resides in contextual menu; applescript cannot access that. There are two work-arounds I can think of: 1. BTT: hover over the playlist and invoke a combo right-click -> u -> return. Or:

tell application "System Events" to tell application process "iTunes"
    set frontmost to true
    repeat 2 times
        tell menu item "Edit Smart Playlist" of menu "File" of menu bar 1 to perform action "AXPress"
        tell checkbox "Live updating" of window 1 to perform action "AXPress"
        tell button "OK" of window 1 to perform action "AXPress"
    end repeat
end tell

Thanks guys for starting this thread!

I have hundreds of smart playlists in my iTunes so toggling Live Updating manually is a real pain.

I had to play with your above answers for a little while to get it working on my El Capitan and Sierra systems, but here is what finally worked for me:

tell application "iTunes"
activate
set frontmost to true
repeat with aPlaylist in (get user playlists)
  set n to name of aPlaylist
  set s to smart of aPlaylist as string
  if s is "true" then
    try
      set view of front browser window to playlist n
      set frontmost to true
      delay 1
      tell application "System Events" to tell application process "iTunes"
        click menu item "Edit Smart Playlist" of menu "File" of menu bar 1
        delay 1

        # To toggle the selection use the following line
        click checkbox "Live updating" of window 1

        # To enable use the below code. To disable, use the below code but change 'false' to 'true'
        #set theCheckbox to checkbox "Live updating" of window 1
        #tell theCheckbox
        #set checkboxStatus to value of theCheckbox as boolean
        #set c to checkboxStatus as string
        #if checkboxStatus is false then click theCheckbox
        #end tell

        delay 1
        click button "OK" of window 1
      end tell
    end try
  end if
end repeat
end tell
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى apple.stackexchange
scroll top