Syncing org-mode with Microsoft Todo
Almost everything I do on a computer happens in Emacs. However, when I am on the go, I use Microsoft Todo to track my tasks. I used to use Wunderlist, Microsoft bought them and build Microsoft Todo as its successor. They kept what I liked about Wunderlist: an API!
I wanted a way to transfer TODO lists from org mode to Microsoft Todo, I built one in five minutes, follow along to see how.
My Todo Lists
Let's imagine that I am going on a trip to New York and I have the following list of items I want to pack:
* Checklist
<List>Trip to New York
** Toiletry
- [ ] toothbrush
- [ ] toothpaste
- [ ] deodorant
- [ ] perfume
- [ ] glasses box
- [ ] contact lenses
** Travel document
- [ ] Wallet
- [ ] Insurance card
- [ ] ID
- [ ] Subway card
This is a regular org-mode file with the addition of the <List>Trip to New York
entry. I searched around to an existing cli to interact with Microsoft Todo and I found tod0. I noticed that it helped me create tasks but not lists. So I created a list manually called "Trip to New York" and figured out how to create a single task in that list:
todocli new "Trip to New York/a task"
The script
I built a script that parses org mode lines in the format above and calls the toodcli
tool:
#!/usr/bin/env python3
import fileinput
import subprocess
import sys
_list = None
for line in fileinput.input():
assert isinstance(line, str)
if "<List>" in line:
_list = line.strip().replace("<List>", "")
if "- [ ] " in line:
res = line.strip().replace("- [ ] ", "")
if not _list:
print("NO LIST FOUND")
sys.exit(1)
print(f"Creating task {res} in list {_list}")
subprocess.check_output(f"todocli new \"{_list}/{res}\"", shell=True)
Finally, all I have to do to create todos from my org file is select a region, call shell-command-on-region
and give it the script above as input.