3

I know that I can define a new iCal event programmatically, by means of AppleScript, defining something like:

 tell application "iCal"
    tell calendar "My Calendar"
        set theCurrentDate to current date
        set newEvent to make new event at end with properties {description:"Test Event Description", summary:"Test Event", location:"Foo Location", start date:date "21/5/2012", end date:date "23/5/2012", allday event:true}
        tell newEvent
            make new sound alarm at end with properties {trigger date: date "21/5/2012 09:00", sound name:"Glass"}
        end tell
    end tell
 end tell

However, I'm not really happy with having to say a precise date in 'trigger date', I'd prefer to be able to specify 'the same day at 9:00' or '2 hours before'. This is is possible via the GUI, but I cannot find the corresponding AppleScript syntax. Is there a reference for this sort of things?

Thank you in advance.

2 Answers 2

2

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

I know, this is an old question, but ...

'the same day at 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 {trigger date: myTriggerDate, sound name:"Glass"}
end tell

'2 hours before' :

NOTES: in your example 2 hours before means 2 hours before 21/5/2012 00:00:00 so 20/05/2012 22:00:00. You need to specify time in your start date if you want something else.

-- 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 {trigger date: myTriggerDate, sound name:"Glass"}
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .