Created
July 15, 2013 12:20
-
-
Save salanki/5999555 to your computer and use it in GitHub Desktop.
Automatically add TODOs to Inbox of Things from iMessages beginning with "TODO:"
This file contains 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
using terms from application "Messages" | |
on message received theMessage from theBuddy for theChat | |
set buddyId to id of theBuddy as text | |
if (makelower(theMessage) begins with "todo:") then | |
set trim1 to trim_line(theMessage, "todo:", 0) | |
set trim2 to trim_line(trim1, " ", 0) | |
tell application "Things 2" | |
set newToDo to make new to do ¬ | |
with properties {name:trim2, notes:"From: " & buddyId} | |
end tell | |
end if | |
end message received | |
end using terms from | |
on makelower(theText) | |
set newText to "" | |
--loop through the letters | |
repeat with loop from 1 to (length of theText) | |
--convert them to lower case | |
set newText to newText & lower(character loop of theText) | |
end repeat | |
--return the new text | |
return newText | |
end makelower | |
on lower(aLetter) | |
--see if the letter is in list of upper case letters | |
considering case | |
set myChar to offset of aLetter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
--if so, then return the lower case version | |
if myChar > 0 then | |
return character myChar of "abcdefghijklmnopqrstuvwxyz" | |
else | |
--else return the original character (it might be a number!) | |
return aLetter | |
end if | |
end considering | |
end lower | |
on trim_line(this_text, trim_chars, trim_indicator) | |
-- 0 = beginning, 1 = end, 2 = both | |
set x to the length of the trim_chars | |
-- TRIM BEGINNING | |
if the trim_indicator is in {0, 2} then | |
repeat while this_text begins with the trim_chars | |
try | |
set this_text to characters (x + 1) thru -1 of this_text as string | |
on error | |
-- the text contains nothing but the trim characters | |
return "" | |
end try | |
end repeat | |
end if | |
-- TRIM ENDING | |
if the trim_indicator is in {1, 2} then | |
repeat while this_text ends with the trim_chars | |
try | |
set this_text to characters 1 thru -(x + 1) of this_text as string | |
on error | |
-- the text contains nothing but the trim characters | |
return "" | |
end try | |
end repeat | |
end if | |
return this_text | |
end trim_line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment