6 Replies Latest reply: Dec 1, 2012 3:07 AM by Ron60
Ron60 Level 1 Level 1 (0 points)

I'm using this script to turn off my ICal alerts while running scripts that conflict with schudule tasks.

 

I have serveral scripts that need to run throughout the day useing this process and some that need ICal alert on as well.

 

Is there a way to have this script not toggle on/off?  Currently, if I run another script while the ICal alert is off it will toggle ICal alerts to an "on" state.

 

Maybe an "if" statement - if "off" then quit,  --------------------------For those scripts which require ICal alerts to remain off.

And a "if" statement - if "off" then click the menu item to it's "on" state.  --For those scripts that require iCal alerts to be on.

 

I don't want it to be a dialog task. These scripts need to run in the background.

 

This is the script I'm currently using:

 

tell application "System Events" to tell process "iCal"

   --click menu item "Preferences…" of menu 1 of menu bar item "iCal" of menu bar 1
   click menu item 3 of menu 1 of menu bar item 2 of menu bar 1

 

   --click button " Advanced " of tool bar 1 of window 1
   click button 3 of tool bar 1 of window 1

 

   --click checkbox "Turn off all alarms" of window 1
   click checkbox 1 of window 1

 

   --click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1
   click menu item 10 of menu 1 of menu bar item 3 of menu bar 1

end tell


tell application "iCal" to quit

 

Any help or advice would be greatly appriciated.  

 

Ron


iMac, Mac OS X (10.7.3)
  • Austin Kinsella1 Level 6 Level 6 (11,520 points)

    Could you give us an idea of the type of schedule taks that iCal alerts will conflict with? And indeed a general idea of the overall scheme.

  • Ron60 Level 1 Level 1 (0 points)

    I use Ical alerts to run several applescripts to control Itunes music.  These scripts run daily changing the playlist as the mood changes at this bar throughout the day. 

     

    Some of the scripts are applescripts and some are automator apps.

     

    Sometimes we want to stray from the daily schuduled playlist and run our personal playlist.

     

    He is what I'm trying to do.....

    I'm using "Big Buttons" application which allows me to create an Iphone app to control my IMac.  This software allows me to create buttons to control Itunes tasks or any other application by assigning applescripts to each button.  It works great!

     

    I want to be able to override the ICal alert tasks by turning them off when I run a simple script to play a new playlist.  Like My Favorite Songs.

     

    So if I make a button and assign a applescript which plays "My Fovorite Songs" playlist, I would like it to turn off ICal alerts before it runs.   Otherwise I might have a schuduled task run during it playing time that changes the playlist to..... for example my "Party" playlist or something other mood playlist I have scheduled.

     

    My scripts are lengthy so I really don't want to add all that info.  I just need to ad the ICal alert section to my script.

     

    Let use this as an example:

     

    tell application "iTunes"

      activate

      play playlist "My Favorite Songs"

    end tell

     

    How do I add to this script to turn "off" ICal alerts if "on"

     

    Then....  I will then like to make another button script to turn ICal alert "on" if the state is "off".

    So using this example...

     

    tell application "iTunes"

      activate

      play playlist "Party Playlist"

    end tell

     

    How do I add to this script to turn "on" ICal alerts if "off" and play this playlist.

     

    My ICal scheduled scripts are designed to wait until the completions of a song before changing mood playlist. So I don't have to worry about disruption of a song if it changes the mood soon after.

     

    I hope this all makes sense and I've given you enough info as to what I'm trying to do.....

     

    Ron

  • Austin Kinsella1 Level 6 Level 6 (11,520 points)

    Thinking ...

  • Ron60 Level 1 Level 1 (0 points)

    Austin thanks for taking the time to help me.  I really do appriciate it!

     

    Do you know if ICal give back infomation regarding check mark fields that are "on" or un-checked?

     

    I was hoping that if it does..... maybe a script can be written something like....  

     

    if button 10 is "on" then

    click menu item 10 of menu 1 of menu bar item 3 of menu bar 1

    if button 10 is "off" then

    quitt

     

    or something like that....    

     

    I only need a simple script to check if ICal alerts is  ON or OFF before taking an action....

     

    I guess if ICal doesn't work that way, it won't be a simple script.

     

    Ron

  • Austin Kinsella1 Level 6 Level 6 (11,520 points)

    There is an old joke here where a tourist, somewhat lost, approaches a local at a crossroads and asks for directions to X. The man thinks for a while, scratches his head, takes his pipe out of his mouth, puts it back, thinks some more and eventually replies "Well, if I were you, I wouldn't start from here at all".

     

    I suspect iCal is not the solution, but rather launchd, the built-in scheduler. Something along these lines:

     

    put your schedule of (starttime, playlistname) in a text file

     

    write an Applescript which gets the name of the current playlist from iTunes and checks it against the scripts playlist property. If they are different ('cos you have used Big Button to change) exit. Otherwise check the file to see what playlist should be running now, and tell iTunes to change if necessary, remembering the playlist name in the playlist property and exit

     

    write a launchd agent to fie this script every 15 minutes (or whatever) (easy enough with property list editor, easier with eg lingon)

     

    There's probably a few wrinkles to iron out ...

  • Ron60 Level 1 Level 1 (0 points)

    Well.....  I got a script to work after trying for several days.   I'm not good at writing scripts so I'm sure there is a better way of writing them.  At least a cleaner way....

     

    I found a script to base mine off of at:

    http://macscripter.net/viewtopic.php?id=30031

     

    Towards the bottom of that website there is a script which is half in German.

    Here is that script::

    ________________________________________________________________________________ ____

     

    tell application "iCal" to activate


    tell application "System Events" to tell process "iCal"

       click menu item 3 of menu 1 of menu bar item 2 of menu bar 1

       click button 3 of tool bar 1 of window 1

    end tell


    tell me to activate


    tell application "System Events" to tell process "iCal"

       set check to value of checkbox 1 of window 1

    end tell


    if check = 0 then


       display dialog "Erinnerungen sind AKTIV!" buttons ["Abbrechen", "Deaktivieren"] default button "Deaktivieren"


       if button returned of result is "Abbrechen" then

           tell application "iCal" to quit

       else

           tell application "System Events" to tell process "iCal"

               click checkbox 1 of window 1

           end tell

           tell application "iCal" to quit

       end if


    else


       display dialog "Erinnerungen sind NICHT aktiv!" buttons ["Abbrechen", "Wieder aktivieren"] default button "Wieder aktivieren"


       if button returned of result is "Abbrechen" then

           tell application "iCal" to quit

       else

           tell application "System Events" to tell process "iCal"

               click checkbox 1 of window 1

           end tell

           tell application "iCal" to quit

       end if


    end if

    ________________________________________________________________________________ _________

     

    So I tested the script to see if it would work...   And it does...  The only thing is it had a dialog function which I don't want to use....  

     

    I came out with two scripts   One to activate and one to disable ICal alarms.

     

    Here they are.........

     

    ---------ICal Alarm Activate Script---------------

     

    tell application "iCal" to activate

     

    tell application "System Events" to tell process "iCal"

    click menu item 3 of menu 1 of menu bar item 2 of menu bar 1

    click button 3 of tool bar 1 of window 1

    end tell

     

    tell me to activate

     

    tell application "System Events" to tell process "iCal"

              set check to value of checkbox 1 of window 1

    end tell

    if check = 0 then

              tell application "iCal" to quit

    else

              tell application "System Events" to tell process "iCal"

                        set check to value of checkbox 1 of window 1

              end tell

              if check = 1 then

                        tell application "System Events" to tell process "iCal"

      click checkbox 1 of window 1

                        end tell

                        tell application "iCal" to quit

              end if

    end if

     

     

    ---------ICal Alarm Activate Disable --------------

     

    tell application "iCal" to activate

     

    tell application "System Events" to tell process "iCal"

    click menu item 3 of menu 1 of menu bar item 2 of menu bar 1

    click button 3 of tool bar 1 of window 1

    end tell

     

    tell me to activate

     

    tell application "System Events" to tell process "iCal"

              set check to value of checkbox 1 of window 1

    end tell

    if check = 1 then

              tell application "iCal" to quit

    else

              tell application "System Events" to tell process "iCal"

                        set check to value of checkbox 1 of window 1

              end tell

              if check = 0 then

                        tell application "System Events" to tell process "iCal"

      click checkbox 1 of window 1

                        end tell

                        tell application "iCal" to quit

              end if

    end if

     

     

    ______________________________________________________________________

     

    Like I mentioned above, I'm very, very green in applescript writing.  I'm sure my scripts looks weird but they works.   Feel free to clean them up for me.....

     

    Hope thiis helps others who need a way to control ICal Alarms.

     

     

    Ron

    I