Skip to content

Instantly share code, notes, and snippets.

@BenjaminVanRyseghem
Last active August 29, 2015 14:15
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 BenjaminVanRyseghem/edac77463aa81498e9a1 to your computer and use it in GitHub Desktop.
Save BenjaminVanRyseghem/edac77463aa81498e9a1 to your computer and use it in GitHub Desktop.
Mail -> Things sync
on theSplit(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to theDelimiter
-- create the array
set theArray to every text item of theString
-- restore the old setting
set AppleScript's text item delimiters to oldDelimiters
-- return the result
return theArray
end theSplit
using terms from application "Mail"
on perform mail action with messages newMessages
repeat with newMessage in newMessages
tell application "Mail"
set taskName to subject of newMessage
set taskNotes to content of newMessage
set myArray to my theSplit(taskName, "@")
set hasDate to (length of myArray is equal to 2)
if length of myArray is equal to 2 then
set dueString to (item 2 of myArray)
set trimmedString to do shell script "echo " & quoted form of dueString & " | sed -e 's/^[ ]*//' | sed -e 's/[ ]*$//'"
set generatedDate to do shell script "/bin/bash -lc \"python ~/scripts/parse.py " & trimmedString & "\""
end if
tell application "Things"
set newtodo to make new to do with properties {name:taskName, notes:taskNotes}
if hasDate then
set due date of newtodo to date generatedDate
end if
end tell
delete newMessage
end tell
end repeat
end perform mail action with messages
end using terms from
@BenjaminVanRyseghem
Copy link
Author

parse.py can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment