• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Determining the default CalendarName in Calendar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Determining the default CalendarName in Calendar
      • From: Bill Vlahos <email@hidden>
    • Re: Determining the default CalendarName in Calendar
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Script wants to access your calendar !
  • Next by Date: month contants and dates...
  • Previous by thread: Determining the default CalendarName in Calendar
  • Next by thread: Re: Determining the default CalendarName in Calendar
  • Index(es):
    • Date
    • Thread