Skip to content

Instantly share code, notes, and snippets.

@JoeGlines
Created April 8, 2022 16:20
Show Gist options
  • Save JoeGlines/dd2ac4f2d3ad8869b2365937d6280066 to your computer and use it in GitHub Desktop.
Save JoeGlines/dd2ac4f2d3ad8869b2365937d6280066 to your computer and use it in GitHub Desktop.
;***********************Read and Write appointments from Calendar**************************.
;http://www.autohotkey.com/forum/viewtopic.php?t=61509&p=379775#379775
olFolderCalendar := 9 ; Outlook.OlDefaultFolders.olFolderContacts
olFolderContacts := 10 ; get constants from visual studio
olAppointmentItem = 1
profileName := "Outlook"
Outlook := ComObjCreate("Outlook.Application")
namespace := Outlook.GetNamespace("MAPI")
namespace.Logon(profileName)
calendar := namespace.GetDefaultFolder(olFolderCalendar)
items := calendar.Items
count := items.Count
msgbox % "calendar items: " count
item := calendar.Items(1)
item1 := "subject: " item.Subject . "`n"
item1 .= "Start: " item.Start . "`n"
item1 .= "Duration: " item.Duration . "`n"
item1 .= "Body: " item.Body "`n"
msgbox % "item1" item1
date := "9/1/2010 9:00:00 AM" ; this works, although the recommended
; format is year/month/date
; hours:minutes:seconds AM/PM
date := "2010/9/1 9:00:00 AM"
msgbox % makeAppointment(Outlook, "auto", "autohotkey rocks", date, "60", "2")
!r::reload
!q::exitapp
makeAppointment(outlook, subject, body, startTime, duration, busyStatus)
{
static olAppointmentItem = 1
, olFree = 0
, olTentative = 1
, olBusy = 2
, olOutOfOffice = 3
item := outlook.CreateItem(olAppointmentItem)
item.Body := body
item.BusyStatus := busyStatus ; olBusy
msgbox % startTime
item.Start := startTime ; 9/1/2010 9:00:00 AM
item.Duration := duration ; 60
item.Subject := subject
return item.save() ; warns about programmatic access with normal settings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment