Last active
August 29, 2015 14:15
-
-
Save BenjaminVanRyseghem/edac77463aa81498e9a1 to your computer and use it in GitHub Desktop.
Mail -> Things sync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
parse.py
can be found here