play a song from within a playlist?

Posted on
Mon Mar 19, 2018 6:51 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

play a song from within a playlist?

Is there any easy way to script the itunes plugin play a song from within an itunes playlist (preferably a random song from within a playlist)?

I am trying to convert over my AppleScripts to python due to the impending loss of AppleScript support. However, one of my favorite Indigo controlled things (a custom chiming grandfather clock with LOTS of different chimes) is heavily dependent on AppleScript. In particular, during most holidays it pulls a random track from a playlist for that holiday.

I think by rewriting the script in Python, I can actually improve upon my old AppleScript version by quite a bit, but first I need to see if this core functionality is possible.

Posted on
Mon Mar 19, 2018 7:40 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: play a song from within a playlist?

No, the plugin doesn't support playlists. But, remember, AppleScript that talks to other apps will continue to work, so if you're using an AppleScript to start a playlist then that will continue to work - just call it via either an external AppleScript or from a Python script using one of the methods outlined in the blog post.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Mar 20, 2018 8:12 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

jay (support) wrote:
No, the plugin doesn't support playlists. But, remember, AppleScript that talks to other apps will continue to work, so if you're using an AppleScript to start a playlist then that will continue to work - just call it via either an external AppleScript or from a Python script using one of the methods outlined in the blog post.


Thanks Jay,

So if I understand this correctly, I could break up my large AppleScript that controls the entire clock chiming system into smaller pieces of AppleScript (say, pull out the 5 lines that have it pull Christmas songs from the Christmas playlist in itunes in Decemeber), save those as separate .scpt files, then use this python command to call those .scpt files from within a larger python script?

Code: Select all
import applescript

# From a file
path_to_script_file = "/Users/jay/Projects/Python/AppleScriptTest/sample.scpt"
my_ascript_from_file = applescript.AppleScript(path=path_to_script_file)

reply = my_ascript_from_file.run()



And all of that will survive the change coming in Indigo WRT Applescript?

That would be pretty cool, because then I could use CP's/variables/etc to manipulate the whole thing rather than having to go back into Indigo proper when I want to, say, change the chime for one day.

I realize this is a pretty absurd use case, and I may literally be the only one here doing something so unusual, but it's probably my family's favorite thing about our entire HA setup.

Posted on
Tue Mar 20, 2018 10:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: play a song from within a playlist?

Yeah, that's one way. Depending on the complexity of everything else the script does though, you may not even need that. If that's all the script does, then you can continue to use the Execute Script action and just point it to the AppleScript that starts the appropriate playlist. That functionality will remain - what won't work are scripts that target Indigo and embedded AppleScripts.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Mar 20, 2018 10:24 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: play a song from within a playlist?

Feel free to post the whole AppleScript over in the Help Converting AppleScripts forum - I'm sure you'll get a variety of suggestions on how to do it. We all might learn some things from that exercise.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Mar 20, 2018 11:07 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

jay (support) wrote:
Feel free to post the whole AppleScript over in the Help Converting AppleScripts forum - I'm sure you'll get a variety of suggestions on how to do it. We all might learn some things from that exercise.



Thanks. I may do that. Would need to redact quite a bit as it's rather full of a fair amount of family data (birthdays, geographical/sports allegiences, alma mater/fight songs, etc). I might be able to distill it down to just the holidays, though, for posting purposes.


jay (support) wrote:
Yeah, that's one way. Depending on the complexity of everything else the script does though, you may not even need that. If that's all the script does, then you can continue to use the Execute Script action and just point it to the AppleScript that starts the appropriate playlist. That functionality will remain - what won't work are scripts that target Indigo and embedded AppleScripts.


I think what appeals to me about rewriting in python and keeping it all embedded in Indigo is the ability for more fine control than I have now. Would be much easier to, say, have a button on a CP to change the chimes just for a day when, say, a favorite college team happens to have a big game that day. Right now, for sports, only football dates are hard coded in, and I just change them all once a year. But there are other sports seasons! I also have recently added in some talkback from the AppleScript to update Indigo variables-- that feature is fairly superfluous, it's just to display some info on a CP-- but I believe that variable updating ability will be lost in the upcoming de-support, right?

Thanks for the suggestions.

Posted on
Tue Mar 20, 2018 3:05 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: play a song from within a playlist?

Professor Falken wrote:
I also have recently added in some talkback from the AppleScript to update Indigo variables-- that feature is fairly superfluous, it's just to display some info on a CP-- but I believe that variable updating ability will be lost in the upcoming de-support, right?


You can use the information in the blog post to get data from AppleScript into a Python script that can then update variables.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 21, 2018 8:52 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: play a song from within a playlist?

I forgot to mention this plugin - it may help you do what you need without the need for scripts.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Mar 22, 2018 6:55 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

Thanks Jay, I'll check that out too.

Posted on
Sun Mar 25, 2018 8:19 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

So I went ahead and started working on changing this applescript over to a python one (and calling external applescripts to talk to itunes). Unfortunately, I literally can't get past the first step (Import apple script).

Code: Select all
embedded script:no module named apple script


I had first tried installing the apple script module using the sudo pip command, but I was getting a terminal error. So following the instructions on this wiki entry, I downloaded the source code from github and installed it. Looking at the terminal comments, it seemed to install. But I am still getting the same error on my embedded script (no module found).

any suggestions?

Posted on
Sun Mar 25, 2018 1:41 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: play a song from within a playlist?

No space between apple and script:

Code: Select all
import applescript


Also, make sure you're running 7.1.x or later.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Mar 25, 2018 1:51 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

Ha, I wish.

I don't have a space in the script (or in the reported error). I couldn't copy from within the Indigo window there, so I just typed it in for the forum. I introduced the error when I transcribed it.

Posted on
Sun Mar 25, 2018 1:52 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

ahh... but I am running 7.03...

Guess I'll have to update

Posted on
Sun Mar 25, 2018 3:21 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: play a song from within a playlist?

Well, upgrading to 7.1 got me past the import Applescript problem, but I seem to have a different issue now with the script timing out.

As per your earlier suggestion, Jay, I'm going to continue this discussion over on the Applescript conversion thread.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests