iTunes Fade Script

Posted on
Mon Dec 04, 2017 5:19 pm
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

iTunes Fade Script

Hey Fellas, how about a conversion to python for this one:

Code: Select all
property tick : 1 -- change volume level by this many each loop
property thismany : 20 -- seconds to wait before making next change to volume

tell application "iTunes"
   repeat
      set snd to sound volume
      if snd is less than or equal to tick then
         set sound volume to 0
         exit repeat
      end if
      set sound volume to (snd - tick)
      delay thismany
   end repeat
   pause
   set snd to sound volume
   set sound volume to 100
end tell


Thanks

--
Korey

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

Re: iTunes Fade Script

No need to convert it since it doesn't target the Indigo Server - it's perfectly fine to keep it running just like that.

However, if you're using the iTunes plugin, you can also do it in Python (with lots of comments to explain):

Code: Select all
import time

tick = 1
thismany = 20

# We need to get the plugin instance in order to call plugin actions
itunesPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.itunes")

# Get the iTunes Server Indigo instance so that we can get the volume.
itunesDevice = indigo.devices[1234567890] # ID of your iTunes server device in Indigo

while True:
   # Save the current sound level as an integer
   snd = int(itunesDevice.states['volume'])
   # Compare to tick
   if snd <= tick:
      # Set the volume to 0 and break out of the while loop
      itunesPlugin.executeAction("setVolume", deviceId=1234567890, props={'volume':0})
      break
   # Decrement the sound by tick
   itunesPlugin.executeAction("setVolume", deviceId=1234567890, props={'volume': snd-tick})
   # sleep thismany seconds
   time.sleep(thismany)
   # Refresh the iTunes device since we have a local copy and it could have changed while
   # we were sleeping
   itunesDevice.refreshFromServer()
# Pause iTunes
itunesPlugin.executeAction("pause", deviceId=135305663)
# Unclear why the next line is in there since you don't seem to be using snd anymore
# and you know that when you get here the volume is 0, but for completeness
snd = 0
# Set the volume back to full
itunesPlugin.executeAction("setVolume", deviceId=1234567890, props={'volume': 100})


Untested, but it's pretty close. You'll obviously want to run this as an external script since it has sleep statements in it so it is by nature a long-running script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Dec 04, 2017 7:13 pm
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: iTunes Fade Script

Thanks Jay!

The last line resets the volume back to 100% so that its ready the next day for playback and volume is not at zero.

--
Korey

Posted on
Tue Dec 05, 2017 9:16 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Fade Script

Korey wrote:
Thanks Jay!

The last line resets the volume back to 100% so that its ready the next day for playback and volume is not at zero.


Right, got that. It's the second to last line I don't think is necessary... :wink:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Dec 05, 2017 9:44 am
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: iTunes Fade Script

jay (support) wrote:
Korey wrote:
Thanks Jay!

The last line resets the volume back to 100% so that its ready the next day for playback and volume is not at zero.


Right, got that. It's the second to last line I don't think is necessary... :wink:



Thats why you are the wizard programmer and I am just a hack! :lol:

--
Korey

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest