So after a long day of trial, error, and crying to StackOverflow (Thanks CJK). I was able to put together something that although might need some more design work, meets all the functionality I've been looking for.
This is for Todoist, but you could literally use it with any IFTTT service, to display the text on your TouchBar.
So two applets to set up in IFTTT to start:
- When new Todoist task is created > Append to text file in Dropbox
- When Todoist task is completed > Append to text file in Dropbox
The ingredients you choose is completely up to you, just make sure the text is the same for both new and completed.
Here's mine:
Repeat for completed tasks - named Completed-Tasks
Now the Apple Script:
tell application "System Events"
set the_folder to the folder "~/Dropbox/Todoist/Tasks"
set the_file to the file "Tasks.txt" in the_folder
set to_do to do shell script "cat " & ¬
quoted form of (POSIX path of the_file as text)
set the_folder2 to the folder "~/Dropbox/Todoist/Tasks"
set the_file2 to the file "Completed-Tasks.txt" in the_folder2
set do_complete to do shell script "cat " & ¬
quoted form of (POSIX path of the_file2 as text)
end tell
set toDo to paragraphs of to_do
set toDoCompleted to paragraphs of do_complete
set Uniquelist to difference(toDo, toDoCompleted)
-- Return a list of the items in setA which aren't in setB.
on difference(setA, setB)
set astid to text item delimiters
set text item delimiters to return & return
set setA to return & setA & return
set text item delimiters to return & linefeed & return
set setB to return & setB & return
set text item delimiters to linefeed
set text item delimiters to setB's text items
set setA to setA's text items
set text item delimiters to ""
set setA to setA as text
if ((count setA) > 0) then
set text item delimiters to return & return
set setA to text items of text 2 thru -2 of setA
else
set setA to {}
end if
set text item delimiters to astid
repeat with i from 1 to ((count setA) - 1)
set item i of setA to item i of setA & " || "
end repeat
return "{\"text\":\"" & (setA as text) & "\",
\"icon_path\":\"" & (POSIX path of ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "Todoist.icns") as text) & "\",
\"background_color\": \"0,0,0,255\"}"
end difference
What's happening?
The AppleScript is converting the two Dropbox files to a list and then comparing both lists (as there's no way to clear the file out when a task is completed). From the comparison, it spits out the non-matched items (still to complete) and returns them to the TouchBar.
How might this help you?
Well... If you have Dropbox. You may litterally use any service with parts of this script for endless possibilities. Please fill me in with either ideas (I'll try and help you build upon the script), or your final results!