Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An add event to Calendar applescript.
--James B. Ackman, 2008-02-06. Based on a script by Kevin Bradley at http://macscripter.net/articles/485_0_10_0_C/
set defCalendar to "Work"
--global ICactive
set theDate to short date string of (current date)
--Get event Summary
display dialog "Enter event name:" default answer " Appointment"
set eName to text returned of the result
--Get date
display dialog "Enter event date:" default answer (theDate as text)
set eDate to text returned of the result
--get time
display dialog "Enter begin time:" default answer "1:00 pm"
set eTime to text returned of the result
set eStart to date (eDate & space & eTime)
set eEnd to (date (eDate & space & eTime)) + (1 * hours)
--get location
display dialog "Which calendar? (Home, Work, ...)" default answer defCalendar
set theCal to text returned of the result
--Set alarm
display dialog "Display alarm how much time before?" default answer "7" buttons {"No Alarm", "hours", "days"} default button 3
set {text returned:theText, button returned:theButton} to the result
if theButton is "days" then
try
set alarmTime to (theText as number) * -60 * 24
on error
set alarmTime to 0
end try
else
if theButton is "hours" then
try
set alarmTime to (theText as number) * -60
on error
set alarmTime to 0
end try
else
set alarmTime to 0
end if
end if
--check if iCal is active
(*
tell application "System Events"
if exists application process "iCal" then
set ICactive to true
else
set ICactive to false
end if
end tell
*)
tell application "Calendar"
activate
try
set newEvent to make new event at end of events of calendar theCal with properties {summary:eName, start date:eStart, end date:eEnd}
if alarmTime ­ 0 then make new sound alarm at end of sound alarms of newEvent with properties {trigger interval:alarmTime, sound name:"Basso"}
on error
--set myCals to name of every calendar whose writable is true
--set theCal to (choose from list myCals with prompt "Attach to which Calendar?" without multiple selections allowed and empty selection allowed) as text
--set newEvent to make new event at end of events of calendar theCal with properties {summary:eName, start date:eStart, end date:eEnd}
display dialog "Error"
end try
--if we opened iCal, we'll close it
--if not ICactive then quit
end tell
  1. I recommended changing the text for the default calendar on line 3 to the calendar of your choice (one that is synced with your Calendar application like work/school gmail account):
  • open 'addEvent_iCal.applescript' with a raw text editor like Sublime Text, TextEdit, nano, etc.
  • Save
  1. Open 'addEvent_iCal.applescript' with the application 'Script Editor'.
  2. Compile
  3. Export as a 'Script' with file extension '.scpt'
  4. Add this file to your ~/Library/Scripts/ folder.
  5. Make sure Scripts are shown on your menu bar:
  • Script Editor --> Preferences --> General --> 'Show script menu in menu bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.