Convert Sonos Music Selection Apple Script to Python

Posted on
Fri Aug 23, 2019 1:29 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Convert Sonos Music Selection Apple Script to Python

Following is a simple script I have been using for years with no problems. I would appreciate any suggestions about converting it to Python.

Code: Select all
if value of variable "pennwoodDay" is "Sunday" then
   set musicList to {"Sonos Play Tunein - WSHU-FM", "Sonos Play Tunein - KBAQ"}
   set musicToday to some item of musicList
   execute group musicToday
else
   set musicList to {"Sonos Play XM - 50s on 5", "Sonos Play XM - 60s on 6", "Sonos Play XM - 70s on 7", "Sonos Play XM - The Blend", "Sonos Play XM - The Bridge", "Sonos Play XM - The Coffee House", "Sonos Play XM - The Loft"}
   set musicToday to some item of musicList
   log musicToday
   execute group musicToday
end if

John R Patrick
Author of
Home Attitude

Posted on
Fri Aug 23, 2019 2:07 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Convert Sonos Music Selection Apple Script to Python

This should be pretty close:

Code: Select all
import random

# First, create lists of the IDs of each of the action groups you want for Sunday and for
# all other days. Make sure they're numbers, not strings (so no quotes around them).
sunday_list = [IDS_OF_ALL_SUNDAY_ACTION_GROUPS_AS_NUMBERS] # so for instance [123456789, 987654321]
other_days_list = [IDS_OF_ALL_OTHER_ACTION_GROUPS_AS_NUMBERS]

var_value = indigo.variables[INSERT_ID_OF_penwoodDay_HERE].value
if var_value == "Sunday":
    indigo.actionGroup.execute(random.choice(sunday_list))
else:
    indigo.actionGroup.execute(random.choice(other_days_list))

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Aug 24, 2019 9:16 am
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Convert Sonos Music Selection Apple Script to Python

This worked perfectly. Thanks!

John R Patrick
Author of
Home Attitude

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests

cron