emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Integrating Org with OS X Reminders (and Siri!)


From: Ken Mankoff
Subject: [O] Integrating Org with OS X Reminders (and Siri!)
Date: Thu, 28 May 2015 09:29:06 -0400

Hi List,

I've written a set of small scripts so that I can use the Reminders.app on my 
iPhone and easily get that information into Org. This means I can pick up the 
phone, say "Hey Siri, Remind me about something", and get that info into Org!

Functionality is basic - items show up in Agenda just like MobileOrg items, 
with a "REFILE" flag set so that I can then refile them. If you mark an item as 
done in Org, that state is not reflected on your iPhone or in Reminders.app 
(although this could be possible with a bit of extra coding).

It is a hacked solution with many parts (rem, rem.py, rem.sh, rem.org, and 
rem.plist), described below:

1) Set up Reminders in iCloud so that Reminders on iPhone and Desktop are 
synced.

2) Install "rem" utility from: https://github.com/kykim/rem

3) Build and put the binary somewhere and check that "rem ls" lists your 
reminders

4) Take following "rem.py" and put it somewhere and make sure it runs and 
prints out all reminders and their details. You probably need to change 
"~/bin/rem" line near the top to the path to your "rem" binary above.

#!/usr/bin/env python

import subprocess

def rem(args):
    '''Execute the 'rem' command with whatever arguments passed and capture 
output'''
    cmd = "~/bin/rem " + args + " |perl -p -e 's/[[:^ascii:]]//g'"
    value = subprocess.check_output(cmd, shell=True)
    return value

def get_lists():
    '''Return a list of the list names'''
    r = rem("ls")
    r = r.split("\n")
    r = r[1:-1]  # drop the "Reminders" title and final newline
    r = [rr.strip() for rr in r]
    l = [rr for rr in r if not rr[0].isdigit()]
    return l

def get_num_items(lists):
    '''Return an integer vector with the number of items in each list'''
    n = []
    for l in lists:
        i = rem("ls " + l)
        i = i.split("\n")
        i = i[2:-1]  # drop the "Reminders" title and final newline
        n.append(len(i))
    return n
        
def reminder_item_to_task(list, item, depth=2, TODO=False):
    task = rem("cat " + list + " " + str(item))
    task = task.split("\n")[:-1]

    TODO = "TODO " if TODO else ""

    title = task[0].split(": ")[1:]
    title = ''.join(title)
    title = '*'*depth + " " + TODO + title

    depth += 1
    
    meta = task[2:4]
    meta = [m.replace('\t','') for m in meta]
    meta = [' '*depth + m for m in meta]
    meta = '\n'.join(meta)
    
    notes = task[4:]
    if len(notes) == 0:
        notes = ''
    else:
        notes[0] = notes[0].split(": ")[1]
        notes = [' '*depth + n for n in notes]
        notes = '\n'.join(notes)

    return title + "\n" + meta + "\n" + notes

if __name__ == "__main__":
    lists = get_lists()
    num = get_num_items(lists)
    for l,n in zip(lists,num):
        for i in range(n):
            t = reminder_item_to_task(l, i+1, TODO=True)
            print t


5) Customize the following "rem.sh" script that should run the "rem.py" and 
produce an Org file. This Org file is tagged REFILE (something I use in my 
Agenda to help me refile MobilOrg generated items).



#!/usr/bin/env bash

SRC=~/tmp/rem.org
DEST=~/Documents/Org/rem.org

echo "# -*- coding: utf-8; eval: (auto-revert-mode 1); -*-" > ${SRC}
echo "#+FILETAGS: REFILE" >> ${SRC}
/Users/mankoff/bin/rem.py >> ${SRC}

# check if it changed
if ! cmp ${SRC} ${DEST} > /dev/null 2>&1
then
    cp ${SRC} ${DEST}
fi


6) Set up a LaunchAgent plist (here com.kenmankoff.rem2org.plist) so that any 
reminders are automatically imported into Org. This file goes into 
~/Library/LaunchAgents and is also customized for your paths...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.kenmankoff.rem2org</string>
        <key>ProgramArguments</key>
        <array>
        <string>/Users/mankoff/bin/rem.sh</string>
        </array>
        <key>WatchPaths</key>
        <array>
                <string>/Users/mankoff/Library/Calendars/</string>
        </array>
</dict>
</plist>

7) Load the LaunchAgent with "launchctl load com.kenmankoff.rem2org.plist"

8) Add a section to your Agenda so that "REFILE" tags items show up:

   (tags "REFILE" ((org-agenda-overriding-header "REFILE")))

9) Add an item on your phone, or check one off. Refresh your Agenda. Items 
should appear/disappear.


Hope someone finds this useful,

  -k.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]