iCal AppleScript, wie kann "am selben Tag um 9" angegeben werden?

1216
zakmck

Ich weiß, dass ich ein neues iCal-Ereignis programmatisch mithilfe von AppleScript definieren kann.

 tell application "iCal" tell calendar "My Calendar" set theCurrentDate to current date set newEvent to make new event at end with properties  tell newEvent make new sound alarm at end with properties  end tell end tell end tell 

Ich bin jedoch nicht wirklich glücklich, wenn Sie unter 'Auslösungsdatum' ein genaues Datum angeben müssen. Ich würde es vorziehen, 'am selben Tag um 9:00' oder '2 Stunden vorher' angeben zu können. Dies ist über die GUI möglich, aber ich kann die entsprechende AppleScript-Syntax nicht finden. Gibt es einen Hinweis für diese Art von Dingen?

Danke im Voraus.

3

2 Antworten auf die Frage

2
kopischke

If you are referring to the natural language input box Lion’s iCal pops up when you click the + button, that functionality does not seem to be exposed to AppleScript.

The reference for this, in fact the first reference for the scripting model of any application, is its own own scripting dictionary – the documented scripting interface you can browse in the Library window of AppleScript editor. iCal’s is in there by default, as is the dictionary of most scriptable applications that come pre-installed with OS X, but you can add any scriptable app by just dropping it on the window (or going the long route through the + button) – it’s a good way to find out if an app is scriptable, BTW, as non-scriptable ones will just refuse to add themselves to the Library.

0
boissonnfive

Ich weiß, das ist eine alte Frage, aber ...

"am selben Tag um 9:00":

-- 1. Get the start date of the event set evtStartDate to start date of newEvent -- 2. Reset the time of that date (=> 00:00) -- Not necessary in your example as you don't specify time so time is already 00:00 tell evtStartDate to set myTriggerDate to it - (its time) -- 3. Add 9 hours to that date set myTriggerDate to myTriggerDate + 9 * hours -- 4. Set this date as the trigger date tell newEvent make new sound alarm at end with properties  end tell 

'2 Stunden vorher':

HINWEISE: in Ihrem Beispiel 2 Stunden vor bedeutet 2 Stunden vor dem 21.05.2012 00:00:00 so 20/05/2012 22:00:00. Sie müssen die Uhrzeit in Ihrem Startdatum angeben, wenn Sie etwas anderes wünschen.

-- 1. Get the start date of the event set evtStartDate to start date of newEvent -- 2. Subtract 2 hours to that date set myTriggerDate to evtStartDate - 2 * hours -- 3. Set this date as the trigger date tell newEvent make new sound alarm at end with properties  end tell