Re: Determining the default CalendarName in Calendar
Re: Determining the default CalendarName in Calendar
- Subject: Re: Determining the default CalendarName in Calendar
- From: Nigel Garvey <email@hidden>
- Date: Sun, 17 May 2015 13:32:01 +0100
Bill Vlahos wrote on Sat, 16 May 2015 11:46:33 -0700:
>AppleScript can create a calendar event using the following code.
>
>tell application "Calendar"
> activate
> tell (first calendar whose name is calendarName)
> set vEventInfo to make new event at end of events with properties
>{summary:theSummary, start date:startDate, end date:endDate,
>description:theDescription, location:theLocation}
>
>How can I remove the requirement to specify the calendarName and have it
>just use whatever is set as the default calendar in the Calendar
>application?
Hi.
This seems to work:
-- Read and analyse Calendar's preferences, returning the default calendar's ID.
-- The sed code outputs the CalDefaultCalendar value if it's quoted (ie. an ID); otherwise the "last selected calendar list item" value.
-- The line containing the latter value is stored and used only if no
CalDefaultCalendar value is returned first.
set defaultCalendarID to (do shell script "defaults read com.apple.iCal | sed -En '
/^.+CalDefaultCalendar [^\\\"]+\\\"([^\\\"]+).+/ { s//\\1/p ; q ; }
/last selected calendar list item/ h
$ { g ; s/^[^=]+[^\\\"]+\\\"([^\\\"]+).+$/\\1/p; }'")
tell application "Calendar"
set defaultCalendar to calendar id defaultCalendarID
name of defaultCalendar -- Test.
end tell
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