Skip to content

Instantly share code, notes, and snippets.

@darrenpmeyer
Created May 21, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenpmeyer/9641de11f9bb183896a34d63b7e5ce9f to your computer and use it in GitHub Desktop.
Save darrenpmeyer/9641de11f9bb183896a34d63b7e5ce9f to your computer and use it in GitHub Desktop.
AppleScript to make a new Notes.app Note in an Exchange account from the currently selected Outlook Calendar Events
-- yes, that is an oddly specific use case; I suspect most people will just use this for
-- reference to solve their own problems ;)
tell application "Microsoft Outlook"
set currentEvents to selected objects
--log currentEvents
repeat with ev in currentEvents
try
set theSubject to the subject of ev
--log theSubject
set theStart to start time of ev
--log theStart
set {year:y, month:m, day:d} to theStart
set theStartTime to the time string of theStart
set strDate to "" & d & ". " & m & " " & y & " " & theStartTime
--log strDate
set theNoteName to "[M] " & theSubject & " @ " & theStartTime
tell application "Notes"
activate
tell account "Exchange"
-- try finding a note with this name
set matchingNotes to my findNoteByTitle("Exchange", theNoteName)
if matchingNotes is {} then
-- activate the existing note!
make new note at folder "Notes" with properties {name:theNoteName}
set newNote to first item of my findNoteByTitle("Exchange", theNoteName)
else
-- create a new note
set newNote to first item of matchingNotes
log newNote
end if
end tell
show newNote
end tell
on error errMsg
display alert errMsg
log errMsg
end try
end repeat
end tell
on findNoteByTitle(accountName, theNoteName)
tell application "Notes"
tell account accountName
-- try finding a note with this name
set matchingNotes to (every note whose name is equal to theNoteName)
log matchingNotes
return matchingNotes
end tell
end tell
end findNoteByTitle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment