4

I am a seasoned developer, but very new to AppleScript.

I would like to change some of the details of an event in a calendar.

I have found the Library in the Script Editor, and made my way to the Calendar section. I’m not at all sure where to go from here.

In particular, I would like to change a detail which is not listed in the Library, so I’m not altogether optimistic. That detail is the time zone, in particular for the start and finish times. This information is in the ical vevent data which is in the raw data.

So far I am still experimenting with reading what is there:

set calendarName to "Work Travel"
set now to date "Wednesday, 1 March 2017 at 12:00:00 am"

tell application "Calendar" to tell calendar calendarName
    set currentEvents to get every event where its start date ≥ now
    repeat with e in currentEvents
        set start to start date of e
    end repeat
end tell

My current system is MacOS 10.12 Sierra.

  • Can you please include the part of the code you've already got (e.g. the part navigating to/selecting a specific calendar entry for modification)? – nohillside Mar 4 '17 at 7:41
  • Nothing really. I have included it in my edited question. – Manngo Mar 4 '17 at 8:08
  • Nigel at MacScripter is the authority on this... macscripter.net/viewtopic.php?pid=119606#p119606 – adayzdone Mar 6 '17 at 16:02
1

Shane Stanley has a library that allows you to modify the time zone: https://www.macosxautomation.com/applescript/apps/Script_Libs.html


Update to my original reply:

In fact, your question prompted me to use the library and I found a bug in the time zone modification code, which is fixed now.

To create (or modify) an event you don't need Calendar. Just use this library.

The code here is almost 100% from the examples, I just added the line about the time zone modification:

use script "CalendarLib EC" -- put this at the top of your scripts
use scripting additions

    set d1 to current date
    set d2 to d1 + 1 * hours
    set theStore to fetch store
    set theCal to fetch calendar "test" cal type cal cloud event store theStore -- change to suit
    set theEvent to create event event store theStore destination calendar theCal event summary "A test event" starting date d1 ending date d2 event location "Around here" event description "some notes" without runs all day
    set theEvent to modify zone event theEvent time zone "Asia/Tokyo"
    store event event theEvent event store theStore
    return event identifier for event theEvent

You can find the available time zones this way:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

current application's NSTimeZone's knownTimeZoneNames() as list

The discussion itself is here: https://lists.apple.com/archives/applescript-users/2017/Dec/msg00006.html

  • Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. – nohillside Dec 4 '17 at 18:07

You must log in to answer this question.

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