Saturday, April 19, 2014

#1 2009-08-09 10:33:22 am

Ptujec
Member
From: Slovenia
Registered: 2009-01-17
Posts: 7
Website

Help! Disable iCal alarms via System Events

This is my code so far. Anyone know how I can check the checkbox "Alle Erinnerungen deaktivieren" (http://qkpic.com/0350f German UI)?

Applescript:

tell application "iCal"
   activate
end tell

tell application "System Events"
   keystroke "," using command down
   keystroke tab using shift down
   keystroke " "
   -- Alle Erinnerungen deaktivieren wählen
end tell



-- tell application "iCal"
--    quit
-- end tell


Filed under: iCal, System

Offline

 

#2 2009-08-09 01:43:45 pm

regulus6633
Member
From: Taulov, Denmark
Registered: 2006-11-01
Posts: 1695
Website

Re: Help! Disable iCal alarms via System Events

Since you're using German, I referenced each item by index. I also included the equivalent reference by element name for each line in English too in case that's helpful.

Applescript:

tell application "iCal" to activate

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


Filed under: iCal, System

Offline

 

#3 2009-08-10 05:07:54 am

Ptujec
Member
From: Slovenia
Registered: 2009-01-17
Posts: 7
Website

Re: Help! Disable iCal alarms via System Events

Wow! Thanks a lot! This is great. It is so annoying to do that by hand before and after a presentation.

This is what I did based on your script:

1. Turn iCal alarms off and Caffeine (http://lightheadsw.com/caffeine) on

Applescript:

----------------
-- This script prepares my Mac for presentations by
-- 1) turning off iCal alarms
-- 2) turning on Caffeine (http://lightheadsw.com/caffeine/)
--
-- by ptujec 08/10/09
--
-- using
-- http://macscripter.net/viewtopic.php?pid=116717#p116717
-- by Hank
----------------

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
display dialog "Change current settings?" buttons ["No", "Ok"] default button "Ok"

if button returned of result is "No" 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

tell application "Caffeine" to activate
tell application "Caffeine" to turn on

2. Turn iCal alarms on again and Caffeine off (with option to quit Caffeine)

Applescript:

----------------
-- This script sets my Mac back to "normal" (after a presentation) by
-- 1) turning on iCal alarms
-- 2) turning off Caffeine (http://lightheadsw.com/caffeine/)
--
-- by ptujec 08/10/09
--
-- using
-- http://macscripter.net/viewtopic.php?pid=116717#p116717
-- by Hank
----------------

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
display dialog "Change current settings?" buttons ["No", "Ok"] default button "Ok"

if button returned of result is "No" 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

tell application "Caffeine" to activate
tell application "Caffeine" to turn off

tell application "Finder" to activate
tell me to activate
display dialog "Quit Caffeine?"
tell application "Caffeine" to quit

3. Turn iCal alarms off/on

Applescript:

----------------
-- This script activate or disactivates iCal alarms
--
-- Source:
-- http://macscripter.net/viewtopic.php?pid=116717#p116717
-- by Hank
--
-- adapted by ptujec 08/10/09

----------------

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
display dialog "Change current settings?" buttons ["No", "Ok"] default button "Ok"

if button returned of result is "No" 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

I included a dialog to make sure the alarms are not already turned off, because the script would turn them on again automatically ... and vice versa. Would be nice if the script could detect the state of the checkbox instead. But my tries failed.

Last edited by Ptujec (2009-08-10 12:34:21 pm)

Offline

 

#4 2009-09-18 05:59:42 am

Lord of the Macs
Member
Registered: 2005-11-28
Posts: 1

Re: Help! Disable iCal alarms via System Events

Hi pjutec,

you can let AppleScript ask for the status of a checkbox by looking for its value. In this case:

Applescript:

tell application "System Events" to tell process "iCal"
   set check to value of checkbox 1 of window 1
end tell

If the variable "check" is 0 the checkbox ist not checked, if it is 1 the checkbox is checked.

Based on this and on this thread so far (thx for the groundwork) I have manipulated the Script for my personal (german) needs:

Applescript:

----------------
-- Dieses Script ändert den Status der Einstellung
-- "Alle Erinnerungen deaktivieren" in iCal (3.0.8)
--
-- Quelle:
-- http://macscripter.net/viewtopic.php?pid=116717#p116717
-- von Hank
--
-- Angepasst:
-- http://macscripter.net/viewtopic.php?id=30031
-- von ptujec 10. Aug. 2009
--
-- Ergänzt von Lord of the Macs 18. Sept. 2009

----------------

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

Hope this will help a little.

Lord of the Macs


Filed under: iCal, System

Offline

 

#5 2009-09-19 08:02:03 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3454

Re: Help! Disable iCal alarms via System Events

My copies of iCal are older versions and don't have the "Turn off all alarms" setting. But it's possible with them to change the "Turn off alarms when iCal is not open" setting by writing directly to iCal's preference file:

Applescript:

do shell script "defaults write com.apple.iCal 'Disable background alarms' 1" -- Check the box.

do shell script "defaults write com.apple.iCal 'Disable background alarms' 0" -- Uncheck the box.

These have to be executed while iCal's not open, so they save having to open iCal — and of course save having to use GUI Scripting.

If you run the following, perhaps you might find some key corresponding to "Turn off all alarms", which you could then use instead of  'Disable background alarms' in the lines above. However, I don't know for sure.  hmm

Applescript:

do shell script "defaults read com.apple.iCal"


NG

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.039 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)