iTunes Script issue (Not directly indigo related!)

Posted on
Fri Jun 08, 2018 5:17 pm
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

iTunes Script issue (Not directly indigo related!)

So I’ve had this AppleScript in my library for years and it’s very handy.. it actually randomly re-orders a playlist rather than just the live shuffle that iTunes does. I found it very handy back in the day but I’ve not used it for years because I kinda just forgot it existed.. but on having rediscovered it and thinking that’d actually be really useful I find that it doesn’t work anymore. Anyone have any ideas on modifying it to work with current versions of iTunes? My hope is I can get it working again and then get indigo to execute it every night to randomise some of my playlists that I use regularly (which I believe isn’t being affected by Indigo’s depreciation of AS as it’s an external script.. have I got that right?). Or indeed has anyone got a more efficient way of getting iTunes to actually re-order the playlist rather than just toggle on shuffle?

The script:

Code: Select all
tell application "iTunes"
   activate
   beep
   set thePlaylist to (get view of front window)
   set trackCount to (get index of last track of thePlaylist)
   set newList to {}
   
   repeat with i from 1 to trackCount
      set newList to newList & (get location of track i of thePlaylist)
   end repeat
   
   repeat with i from length of newList to 1 by -1
      set current_item to (random number from 1 to i)
      tell newList
         set temp to item i
         set item i to item current_item
         set item current_item to temp
      end tell
   end repeat
   
   set oldPlaylist to (get name of thePlaylist as string)
   delete thePlaylist
   
   set ranPlaylist to (make new user playlist)
   set name of ranPlaylist to oldPlaylist
   
   repeat with i from 1 to (get count of newList)
      try
         add item i of newList to ranPlaylist
      end try
   end repeat
   beep
   display dialog "The playlist " & (get name of ranPlaylist as string) & " with " & trackCount & " tracks was randomized."
   
end tell


And the error:

Code: Select all
error "iTunes got an error: Can’t get location of track 1 of user playlist id 83267 of source id 67." number -1728 from location of track 1 of user playlist id 83267 of source id 67

Computer says no.

Posted on
Fri Jun 08, 2018 10:38 pm
virgahyatt offline
Posts: 132
Joined: Jan 11, 2014

Re: iTunes Script issue (Not directly indigo related!)

Where in the script is it triggering the error? If you run it in Script Editor, especially with the log showing it should help figure it out.

Posted on
Sat Jun 09, 2018 2:56 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: iTunes Script issue (Not directly indigo related!)

The script is in ~/Library/iTunes/Scripts and the error in the script editor is the one I posted in the original post (In iTunes itself the error doesn’t format correctly.). It all seems to focus around the ‘location’ element of the script but I haven’t the faintest clue how to fix that, or if it even still can be with the crippled iTunes AppleScript support these days.
Attachments
Untitled.png
Untitled.png (164.24 KiB) Viewed 1749 times

Computer says no.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests