DizzyJ

Q: Using Automator to gradually increase volume

I want to create an Automator iCal script that plays my favorite Sunday morning internet radio cast (the great jazz on WHPK-FM Chicago), starting with zero volume and rising to my normal volume listening level over five minutes. I can't figure out how to set a volume variable.

 

I found this conversation, but adding

 

          for((i=0;i<50;i++)); do

osascript -e "set volume output volume $i"

done

 

into a Run Applescript window returned a "The workflow has stopped because an error occurred while converting the data" error.

 

This was my first attempt at using Applescript, so I could have that completely wrong.

 

Any suggestions or corrections? I'd love to be wakened gradually Sunday mornings to my favorite broadcast. I'm running the latest version of iTunes, OSX and Automator.

 

Thanks

MacBook Air, Mac OS X (10.7)

Posted on Jan 22, 2012 11:56 AM

Close

Q: Using Automator to gradually increase volume

  • All replies
  • Helpful answers

  • by red_menace,Helpful

    red_menace red_menace Jan 22, 2012 12:38 PM in response to DizzyJ
    Level 6 (15,526 points)
    Desktops
    Jan 22, 2012 12:38 PM in response to DizzyJ

    The problem is that you are trying to use a shell script in a Run AppleScript action.

     

    If you are using other actions to initially set the volume to 0 and start the playlist, the following Run AppleScript script should do what you want, otherwise some extra steps will need to be taken to get whatever the "normal listening volume" is.

     

    on run {input, parameters}

     

      set desiredVolume to 75 -- set to regular listening level

     

      set interval to (5 * minutes) -- start to finish time

      set waitTime to interval div desiredVolume -- spread out over interval time

     

      repeat with X from 1 to desiredVolume

        set volume output volume X

        delay waitTime

      end repeat

     

      return input

    end run

  • by DizzyJ,

    DizzyJ DizzyJ Jan 22, 2012 1:15 PM in response to red_menace
    Level 1 (0 points)
    Jan 22, 2012 1:15 PM in response to red_menace

    Thanks, red_menace. I'm not able to get that to work.

     

    Screen Shot 2012-01-22 at 3.09.44 PM.png

    (For testing purposes, I set the interval to 1 minute). The rest of the Automator script works (the beginning stuff is to connect to the drive I store my music library on, then connect with the internet radio station), but once it hits the Applescript, nothing happens.

     

    I notice that X isn't defined. Could that be the problem?

  • by red_menace,Helpful

    red_menace red_menace Jan 22, 2012 1:47 PM in response to DizzyJ
    Level 6 (15,526 points)
    Desktops
    Jan 22, 2012 1:47 PM in response to DizzyJ

    The variable X is defined for the repeat loop.  The script as posted works for me - I can watch the volume setting rise in the System Preferences > Sound > Output pane, and I see from your workflow image that the Run AppleScript action successfully completes.

     

    Is the output device set to something that is controllable (can you manually change the volume setting)?  You can run the following in the AppleScript Editor:

     

    get output volume of (get volume settings)

     

    If the result is missing value then the output device is not controllable (the output is via HDMI to a TV, for example).

  • by DizzyJ,Solvedanswer

    DizzyJ DizzyJ Jan 22, 2012 2:24 PM in response to red_menace
    Level 1 (0 points)
    Jan 22, 2012 2:24 PM in response to red_menace

    Thanks, Red.

     

    I figured out the problem: your script adjusted output volume, not iTunes volume. I did a little searching and adjusted to script to tell iTunes to change the volume:

     

    on run {input, parameters}

     

              tell application "iTunes"

                        set the sound volume to 5 -- set initial volume

     

                        set desiredVolume to 50 -- set to regular listening level

     

                        set interval to (3.5 * minutes) -- start to finish time

                        set waitTime to interval div desiredVolume -- spread out over interval time

     

                        repeat with X from 1 to desiredVolume

                                  set the sound volume to X

      delay waitTime

                        end repeat

     

              end tell

     

              return input

    end run

     

     

    That works just dandy. Now I can attach it to iCal and enjoy my Sunday jazz. ¡Mucho gracías!