I put together an AppleScript on Automator that has the goal of
- taking text (in a pre-determined format)
- extracting the dates/times
- creating macOs Calendar events with these dates/times
The script works but fails when I try to add hours to the appointment date/time. I’d need the events to be +6 hours ahead of the times in the text due to my timezone.
Sample data:
4/29/24 - 2:30pm-3:30pm - XYASHDK
4/29/24 - 6:30pm-9:30pm - DLHEOSH
AppleScript:
{On Automator,
“Get Specified Text” with above data is followed by
“Extract dates from Text” followed by this script}
on run {input, parameters}
set apptList to input
repeat with i from 1 to count of apptList
set appt to item i of apptList
set AppleScript's text item delimiters to " - "
set stringItems to text items of appt
set apptDate to item 1 of stringItems
set AppleScript's text item delimiters to ""
set apptTimes to item 2 of stringItems
set AppleScript's text item delimiters to "-"
set hoursItems to text items of apptTimes
set apptBegTime to item 1 of hoursItems
set apptEndTime to item 2 of hoursItems
set apptBegin to date (apptDate & " " & apptBegTime)
set apptEnd to date (apptDate & " " & apptEndTime)
set apptBeginTZ to ((hours of apptBegin) + 6)
set apptEndTZ to ((hours of apptEnd) + 6)
tell application "Calendar"
tell calendar "ABC"
make new event with properties {summary:"busy", start date:apptBeginTZ, end date:apptEndTZ}
end tell
end tell
end repeat
end run
As above, I’ve tried adding N hours to the final appointment time but get the following error:
The action “Run AppleScript” encountered an error: “Calendar got an
error: Can’t make 8 into type date.”
Would you have any suggestions on how to accomplish adding N hours to the appointment times?