2 Replies Latest reply: Feb 3, 2013 7:06 AM by alex149
alex149 Level 1 Level 1 (0 points)

here is the sctipt ive tried to write, its not finished so some of the things my seem a bit weird at the moment but here it is as it stands

 

global okflag

set okflag to false

set front_app to (path to frontmost application as Unicode text)

 

-- check if iTunes is running

tell application "System Events"

          if process "iTunes" exists then

                    set okflag to true --iTunes is running

          end if

end tell

 

if okflag is true then

 

          set Timer to ""

  display dialog "Sleep Time (Minutes)" default answer Timer buttons {"Cancel", "OK"} default button 2

          set Timer to text returned of the result

 

          delay Timer * 60

 

          tell application "iTunes"

                    set currentVolume to the sound volume

                    if (player state is playing) then

                              repeat

                                        --Fade down

                                        repeat with i from currentVolume to 0 by -1

                                                  set the sound volume to i

                                                  delay 1

                                        end repeat

                                        pause

                                        --Restore original volume

                                        set the sound volume to currentVolume

                                        exit repeat

                              end repeat

 

                    if okflag is false then

 

                    display dialog "iTunes not playing" buttons {"OK"} default button 1 with icon stop

 

                    end if

                    end

 

it doesnt seem to work after the tell "iTunes part i copied and pasted from another applescript

(the purple text)


MacBook Air, Mac OS X (10.7.1)
  • red_menace Level 6 Level 6 (14,780 points)

    Each if...then and tell statement containing multiple statements needs to be closed with an end if and end tell, respectively.  It looks like something got mangled when pasting in the other script - I'm guessing it should be something like:

     

    global okflag

    set okflag to false

    set front_app to (path to frontmost application as Unicode text)

     

    -- check if iTunes is running

    tell application "System Events"

      if process "iTunes" exists then

        set okflag to true --iTunes is running

      end if

    end tell

     

    if okflag is true then

     

      set Timer to ""

      display dialog "Sleep Time (Minutes)" default answer Timer buttons {"Cancel", "OK"} default button 2

      set Timer to text returned of the result

     

              delay Timer * 60

     

      tell application "iTunes"

        set currentVolume to the sound volume

        if (player state is playing) then repeat

          --Fade down

          repeat with i from currentVolume to 0 by -1

            set the sound volume to i

            delay 1

          end repeat

          pause

          --Restore original volume

          set the sound volume to currentVolume

          exit repeat

        end repeat

      end tell

     

    else

      display dialog "iTunes not playing" buttons {"OK"} default button 1 with icon stop

    end if


  • alex149 Level 1 Level 1 (0 points)

    cheers for this, id completely forgotten about this thread, i found a work around for it by just writing my own script for it, that and a few modifications:

     

    global okflag

    set okflag to false

    set front_app to (path to frontmost application as Unicode text)

     

    -- check if iTunes is running

    tell application "System Events"

              if process "iTunes" exists then

                        set okflag to true --iTunes is running

              end if

    end tell

     

    if okflag is true then

              set CV to output volume of (get volume settings)

              tell application "iTunes"

                        set currentVolume to the sound volume

                        if (player state is playing) then

                                  repeat

      --Fade down

                                            repeat with i from currentVolume to 0 by -1

                                                      set the sound volume to i

                                                      delay 5.0E-4

                                            end repeat

      pause

      --Restore original volume

                                            set the sound volume to currentVolume

                                            exit repeat

                                  end repeat

                        else

                                  set the sound volume to 0

      play

                                  repeat with j from 0 to currentVolume by 1

                                            set the sound volume to j

                                            delay 1.0E-4 * (CV)

                                  end repeat

                        end if

              end tell

              tell application front_app

      activate

              end tell

    end if