Re: iCal alarm scripts
Re: iCal alarm scripts
- Subject: Re: iCal alarm scripts
- From: "Nigel Garvey" <email@hidden>
- Date: Mon, 11 Jan 2010 19:30:53 +0000
Paul Berkowitz wrote on Sun, 10 Jan 2010 21:33:49 -0800:
>The only way to get a rough-and-ready hope of a solution here would be to
>get (current date), set a variable (say theTime) to it, then set the seconds
>of theTime to 0. (It's probably been a few seconds since the alarm was
>called, and in any case, the alarm would set to the minute, not second.)
>
>Then go through every calendar, checking for 'every event whose start time „
>theTime' (which could be a LOT of events). Then go through every such event,
>getting 'every display alarm of it whose trigger date = theTime', same for
>every sound alarm, etc, and every type of alarm which you expect or use.
>Hopefully, there's only one alarm that went off at exactly that time, so you
>can probably quite the two repeat loops (events and calendars) when you find
>one. Then get the summary of the event in question and that's your answer.
>
>It could give you the wrong answer if there's more than one alarm that went
>off at the same time (or else, don't quit the repeat loop but get all of
>them), and it could take a very long time.
>
>Frankly, I don't think it's worth it.
An alternative which _might_ be a bit faster would be to ask iCal for
the 'open file alarms of events of calendars whose filepath is [URL of
the script file]'. This returns an AppleScript list of lists of lists,
the innermost lists of which contain either nothing or just the alarms
which trigger the script. Iterating through the lists should be faster
than iterating through the application and only the presented alarms
need be checked. The relevant calendars and events can be referenced
through the index values of the loop variables. As with Paul's outline,
this does _not_ work with repeated events.
on myEvent()
set now to (current date)
set leeway to 5 -- Allow, say, 5 seconds for the script to respond
to the alarm.
tell application "System Events" to set myUrl to URL of (path to me)
tell application "iCal" to set myInstances to (open file alarms of
events of calendars whose filepath is myUrl)
return result
--> A list containing lists corresponding to the calendars,
containing lists
--> corresponding to the events, containing nothing or matching alarm(s).
set evntCal_Indices to {}
repeat with c from 1 to (count myInstances)
set thisCal to item c of myInstances
repeat with e from 1 to (count thisCal)
set thisEvnt to item e of thisCal
repeat with alrm from 1 to (count thisEvnt)
tell application "iCal" to set timeDiff to (start date of
event e of calendar c) + (trigger interval of item alrm of thisEvnt) *
minutes - now
if (timeDiff > -leeway) and (timeDiff < leeway) then set end
of evntCal_Indices to {e, c}
end repeat
end repeat
end repeat
return evntCal_Indices -- event/calendar index pairs.
end myEvent
set candidates to myEvent()
--> {{11, 4}} -- One candidate found: event 11 of calendar 4.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden