Here is a walkthrough of how I built a shortcut to import and delete calendar files from my iCloud calendar.
I hope this can be useful for you in building your own shortcuts or modifying this one to suit your needs.
TL;DR
- Apple Shortcuts: Import & Delete Calendar Files
- Click the link above to download the Apple Shortcut to your Mac and set the folder path to your
Downloadsfolder. - Download calendar files (
.ics) to theDownloadsfolder. - Run the shortcut to import the events to your Apple Calendar and delete the files from the
Downloadsfolder.
Apple Shortcut's Structure
Open the Calendar App
- Use the
Open Appaction to open the Calendar app.- The shortcut works smoother if the Calendar app is open at the start.
Find and Get the Calendar Files
- Use the
Get Contents of Folderaction to get the files from theDownloadsfolder. - Use the
Filter Filesaction to filter the files with the.icsextension.
Notify the User
- Use the
Countaction to count the number of files. - Use the
Show Notificationaction to display the number of files found.- This gives the user an estimate of how long the import will take.
Import the Calendar Files
- Use the
Repeat with Eachaction to loop through the files. - Use the
Open Fileaction to open the file (Repeat Item) in the Calendar app. - Use the
Run AppleScriptaction to execute the script to automate clicking theOKbutton when prompted by the Calendar app.- The script is provided in the section below.
- End the
Repeat with Eachaction.
Delete the Calendar Files
- Repeat the steps to find and get the calendar files.
- Use the
Delete Fileaction to delete the files from theDownloadsfolder. - Why duplicate the shortcut steps? For some reason, using the
Delete Fileaction after theOpen Fileaction does not work smoothly after theRun AppleScriptaction.
Hide the Calendar App
- Use the
Hide Appaction to hide the Calendar app.
AppleScript to Automate Importing Calendar Events
This AppleScript automates the process of importing calendar events in the Calendar app on macOS. It mainly clicks the OK button when prompted by the Calendar app to import an event or skip already-imported events.
calendar-event-importer.applescript
-- Script Name: Calendar Event Importer
-- Version: 1.1 - Improved script with timeout mechanism
-- Usage: Use this script to automate importing calendar events in the Calendar app on macOS.
-- Function: Check if the Calendar event window is open
on isEventWindowOpen(timeoutSeconds)
set startTime to current date
repeat until (existsEventWindow() or ((current date) - startTime) > timeoutSeconds)
delay 0.5
end repeat
return existsEventWindow()
end isEventWindowOpen
-- Function: Check if the event window exists
on existsEventWindow()
tell application "System Events"
tell process "Calendar"
if exists button "OK" of window 1 then
return true
end if
end tell
end tell
return false
end existsEventWindow
-- Main script execution
try
-- Adjust the delay as necessary to ensure the event window has time to open
delay 2
</span><span class="c1">-- Set timeout period (in seconds) for event window to open</span><span class="w">
</span><span class="k">set</span><span class="w"> </span><span class="nv">timeoutPeriod</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="c1">-- Check if the event window is open within the timeout period</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="nv">isEventWindowOpen</span><span class="p">(</span><span class="nv">timeoutPeriod</span><span class="p">)</span><span class="w"> </span><span class="k">then</span><span class="w">
</span><span class="k">tell</span><span class="w"> </span><span class="nb">application</span><span class="w"> </span><span class="s2">"System Events"</span><span class="w">
</span><span class="k">tell</span><span class="w"> </span><span class="nv">process</span><span class="w"> </span><span class="s2">"Calendar"</span><span class="w">
</span><span class="nv">click</span><span class="w"> </span><span class="nb">button</span><span class="w"> </span><span class="s2">"OK"</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="na">window</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="k">end</span><span class="w"> </span><span class="k">tell</span><span class="w">
</span><span class="k">end</span><span class="w"> </span><span class="k">tell</span><span class="w">
</span><span class="k">else</span><span class="w">
</span><span class="c1">-- Event window did not open within timeoutPeriod. Skipping event.</span><span class="w">
</span><span class="k">end</span><span class="w"> </span><span class="k">if</span><span class="w">
end try
How to Import and Use the Apple Shortcut
This automation uses the Shortcuts on Mac.
You can get it on your Mac by clicking on the Import & Delete Calendar Files link.
You will be prompted with three questions:
- Which folder do you want to import the calendar files from? (Default: Downloads)
- Folder path (same as above)
- Do you want to delete the calendar files after importing them? (Default: Yes)
After answering the questions, the shortcut will be added to your Shortcuts app on your Mac.
To run the shortcut:
- Download the calendar files (
.ics) to the folder you specified. - Open the Shortcuts app and run the shortcut.
- The events will be imported to your Apple Calendar, and the files will be deleted from the folder.

Top comments (0)