Display selectable list of playlists?

Posted on
Sun Mar 05, 2017 12:04 pm
Different Computers offline
User avatar
Posts: 1329
Joined: Jan 02, 2016
Location: East Coast

Display selectable list of playlists?

So we can get the list of playlists via
Code: Select all
tell application "iTunes"
  get name of playlists
end tell


But I'm immediately stumped on how I might dynamically get the result into a control page. The only idea I have is to make it some sort of set of variable values, but wow does that seem cludgey given that I have over 100 playlists.

Any other way of doing it?

Refugee from SmartThings and so happy to be on Indigo now.
Sierra on an i5 running Harmony Hub, Hue, Security Camera, DomoPad, EPS Device Extensions EPS Smart Dimmer, MatplotLib, Plex, Scale Adapters, uniFiAP, Wunderground.

Posted on
Sun Mar 05, 2017 3:21 pm
bkmar1192 offline
Posts: 269
Joined: Sep 12, 2015

Re: Display selectable list of playlists?

I have hacked together a scrollable list for my playlists. I have been considering making it a plugin but haven't got around to it yet. I will try to explain how I have it working. This is very custom for my implementation so you might need to dig into it make it you own.

(note: I use my Dynamic Control plugin to mimic a scroll bar. I can explain that if/when you have this working if you want)

In iTunes:
- Create folder called "Indigo Music"
- Put all the playlists you want displayed in Indigo in there

Indigo Variables:
- PlaylistCategory (set the value to "Indigo Music") - needs to match the folder name created above
- CurrentPage (set to "1")
- TotalPages (set to "0")
- Station_[1-10] (i.e. Station_1, Station_2, etc)

Indigo Trigger:
- Trigger on changes to CurrentPage
- run the following Applescript:

Code: Select all
set pagenumber to value of variable "CurrentPage"
--set pagenumber to 2

set startcount to (10 * (pagenumber - 1)) + 1
set endcount to startcount + 9
set playlistgroup to {}
set activeplaylists to {}
set foldername to value of variable "PlaylistCategory"

--Get all playlist in folder
tell application "iTunes"
   set playlistcount to count of playlists
   
   -- get all playlist in Indy Folder
   repeat with currentplaylist from 1 to playlistcount
      try
         if (name of parent of playlist currentplaylist as string) = foldername then
            set end of playlistgroup to name of playlist currentplaylist as string
         end if
      end try
   end repeat
end tell

set value of variable "TotalPages" to (round ((count of playlistgroup) / 10) + 0.4)
--log (round ((count of playlistgroup) / 10) + 0.4)

--create list based on page number
set playlistgroupcount to length of playlistgroup
if endcount > length of playlistgroup then
   set endcount to length of playlistgroup
end if

repeat with activeplaylist from startcount to endcount
   --log item activeplaylist of playlistgroup
   set end of activeplaylists to item activeplaylist of playlistgroup
end repeat

--clear variable list
repeat with itemnumber from 1 to 10
   set station to "Station_" & itemnumber
   set value of variable station to ""
   --log "Clear Station" & itemnumber
end repeat

--load variable list
repeat with itemnumber from 1 to length of activeplaylists
   set station to "Station_" & itemnumber
   tell application "iTunes"
      set trackcount to count of tracks in user playlist (item itemnumber of activeplaylists)
   end tell
   --set numbertracks to tracks in user playlist (item itemnumber of activeplaylists)
   set value of variable station to (item itemnumber of activeplaylists) & " (" & trackcount & ")"
   --log "Setting Station" & itemnumber & " to " & item itemnumber of activeplaylists
end repeat


Control Page:
- Add value of Station_[1-10]
- Clicking on each value loads the corresponding playlist (I perform some other magic here so can't easily give the specific code.
- Add an icon to scroll up the list that runs the following:
Code: Select all
maxpages = int(indigo.variables["TotalPages"].value)
currentpage = int(indigo.variables["CurrentPage"].value)

if currentpage > 1:
   currentpage = currentpage - 1
   indigo.variable.updateValue("CurrentPage", str(currentpage) )

- Add an icon to scroll down the list that runs the following code
Code: Select all
maxpages = int(indigo.variables["TotalPages"].value)
currentpage = int(indigo.variables["CurrentPage"].value)

if maxpages > currentpage:
   currentpage = currentpage + 1
   indigo.variable.updateValue("CurrentPage", str(currentpage) )

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests