Still need help: Get Indigo variable from ext AppleScript

Posted on
Tue Dec 04, 2018 2:05 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Still need help: Get Indigo variable from ext AppleScript

I have a variable list within Indigo that specifies iTunes playlists linked to keypad link buttons. When a button is pressed, the playlist name linked to that button (a variable identified with the button) is set as variable "KPL_iTunes_Playlist" and an external script is called:

Code: Select all
use application "IndigoServer"
set IndigoPlaylist to value of variable "KPL_iTunes_Playlist"
tell application "iTunes"
   reveal playlist "Music"
   reveal playlist IndigoPlaylist
end tell
(other stuff)
tell application "iTunes" to play playlist IndigoPlaylist


How do I make the variables available to the external script, assuming that "use application" won't work in 7.3? Push or pull is OK.
Last edited by BillC on Sat Jun 15, 2019 8:40 am, edited 2 times in total.

Posted on
Wed Dec 05, 2018 10:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Fetching Indigo variable from external AppleScript

How is this script executed? From Indigo? From elsewhere? There are a variety of choices, but we need to understand from where/how the script is run.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 05, 2018 11:17 am
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Fetching Indigo variable from external AppleScript

Within Indigo, called as an external (linked) script by an action group, triggered by the kpl button press.

Posted on
Wed Dec 05, 2018 12:35 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Fetching Indigo variable from external AppleScript

Ok, that's pretty easy then. Create an external Python script to be run instead of your external AppleScript:

Code: Select all
import applescript

# Get the indigoPlaylist value
indigoPlaylist = indigo.variables[IDOF_indigoPlaylist].value

# Create your AppleScript and substitute in the indigoPlaylist value
script_source = '''
set IndigoPlaylist to "{}"
tell application "iTunes"
   reveal playlist "Music"
   reveal playlist IndigoPlaylist
end tell
# other stuff that your AppleScript does
tell application "iTunes" to play playlist IndigoPlaylist
'''.format(indigoPlaylist)

script_instance = applescript.AppleScript(source=script_source)
script_instance.run()


Then run it as an external Python script. The key here is to make sure that the AppleScript has the appropriate substitution markers in it so that you substitute the variable value into the right spot in the script. In this case, the line set IndigoPlaylist to "{}" is the critical line. When you call the .format() method on the script string, it will substitute the parameters for each occurrence of {}. In this case you only specify one substitution (the playlist name) and one parameter to the format() method.

Then, when the script is complete, we compile and run the AppleScript.

There are other ways to do this as well but this one was the one I'd use.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 05, 2018 12:39 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Fetching Indigo variable from external AppleScript

Thanks, Jay. I’m an absolute newbie at Python, this will give me something to get started with.
Last edited by BillC on Sat Jun 15, 2019 8:38 am, edited 2 times in total.

Posted on
Mon Dec 17, 2018 12:46 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Fetching Indigo variable from external AppleScript

@jay, one clarification: Will the lines in the above external python script

Code: Select all
use application "IndigoServer"
set IndigoPlaylist to "{}"

work in Indigo 7.3 when direct applescripting has been removed?

Posted on
Sat Jun 15, 2019 9:28 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Still need help: Get Indigo variable from ext AppleScri

The first line won't work, since it's somewhat like a "tell" statement.

The second line doesn't use anything specific that's presented by the Indigo Server, so it will work. However, it doesn't actually seem to do anything other than set an AppleScript variable called IndigoPlaylist to the string "{}" which it apparently never actually uses. There's got to be more to the script than that, and that's what needs to be inspected to see if it will continue to work.

Point being, that script as you've shown it doesn't actually do anything, so if that's the entirety of the script then it's completely unnecessary.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Jun 15, 2019 9:31 am
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Still need help: Get Indigo variable from ext AppleScri

Sorry for the snippet, referred to this in your post above in the thread:

Code: Select all
import applescript

# Get the indigoPlaylist value
indigoPlaylist = indigo.variables[IDOF_indigoPlaylist].value

# Create your AppleScript and substitute in the indigoPlaylist value
script_source = '''
use application "IndigoServer"
set IndigoPlaylist to "{}"
tell application "iTunes"
   reveal playlist "Music"
   reveal playlist IndigoPlaylist
end tell
(other stuff)
tell application "iTunes" to play playlist IndigoPlaylist
'''.format(indigoPlaylist)

script_instance = applescript.AppleScript(source=script_source)
script_instance.run()


Original problem:
I have a variable list within Indigo that specifies iTunes playlists linked to keypad link buttons. When a button is pressed, the playlist name linked to that button (a variable identified with the button) is set as variable "KPL_iTunes_Playlist" and an external script is called:

Code: Select all
use application "IndigoServer"
set IndigoPlaylist to value of variable "KPL_iTunes_Playlist"
tell application "iTunes"
   reveal playlist "Music"
   reveal playlist IndigoPlaylist
end tell
(other stuff)
tell application "iTunes" to play playlist IndigoPlaylist


How do I make the variables available to the external script, assuming that "use application" won't work in 7.3? Push or pull is OK.

Posted on
Sun Jun 16, 2019 1:01 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Still need help: Get Indigo variable from ext AppleScri

Sorry, that was a copy/paste error (it was in your original script but was unnecessary as Indigo wasn't being targeted), so the use line is unnecessary. I've edited my original reply to remove that line and fix a comment so that it'll compile in AppleScript correctly.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 16, 2019 2:27 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Still need help: Get Indigo variable from ext AppleScri

Thanks, Jay. Appreciate the help.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests