Automatic Tag Generator for DayOne Journals synced with Dropbox

Here’s how I created a system to automatically sync up keywords to tags in DayOne Journal. The journal is stored on my Dropbox, so if you have it in iCloud, I don’t know what you’re going to do.

First Step: Get text list of tags in a text file: (do this in the entries folder of your DayOne Journal, cd to it, if you can’t, google-fu.)

find . -type f |xargs sed -n “/<array>/,/<\/array>/p”|grep “<string>”|sed ‘s/<[^>]*>//g’|sed “s/^[ \t]*//”|tr -d ‘\011’|sort -f|uniq > tags.txt

Then copy this tags.txt folder to your home directory. Edit the file, be careful of phrases in XML that would confuse the system, Weather, Apple, DTD, String – that sort of thing, also be very careful around TLA’s as they can have unintended side effects. The later scripts that do the keyword searches don’t give a damn about cases, so your keywords or your KeYwOrDs will be equivalent.

You’ll need two more scripts. This one adds tags based on keywords passed to it as parameters: (be VERY careful, little L and capital I look very much the same, read man pages, yo)

tag.sh:

#!/bin/bash

cd /Users/username/Dropbox/Apps/Day\ One/Journal.dayone/entries

find . -type f -print0 |xargs -0 grep -L “<string>”$1″</string>”| xargs grep -li “”$1″” |xargs grep -l “<key>Tags</key>”|xargs -I file /usr/libexec/PlistBuddy -c “add Tags:Key string “$1″” file

find . -type f -print0 |xargs -0 grep -L “<string>”$1″</string>”| xargs grep -li “”$1″” |xargs grep -L “<key>Tags</key>”|xargs -I file /usr/libexec/PlistBuddy -c “add Tags array” file

find . -type f -print0 |xargs -0 grep -L “<string>”$1″</string>”| xargs grep -li “”$1″” |xargs grep -l “<key>Tags</key>”|xargs -I file /usr/libexec/PlistBuddy -c “add Tags:Key string “$1″” file

Next, you’ll need another script called updatetags.sh, looks like this:

#!/bin/bash
cat /Users/andy/Dropbox/Apps/Day\ One/tags.txt|xargs -n 1 /Users/andy/tag.sh

The last bit will be a new LaunchAgent, so go to ~/Library/LaunchAgents and mock up a plist file by copying one from there, if you need an example, try this:

more ~/Library/LaunchAgents/com.andymchugh.tag.plist
<?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>org.andymchugh.tag</string>
<key>ProgramArguments</key>
<array>
<string>/Users/andy/updatetags.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>00</integer>
<key>Hour</key>
<integer>06</integer>
</dict>
</dict>
</plist>

The name of the LaunchAgent has to be unique and the inside name (<string>org.andymchugh.tag</string>) should match the file name like you see here. Swap out the com bit for org, and forget the plist bit. This script will run every day at 6am. You can flavor it to your liking.

Then the final command to tie it all together:

launchctl load -w com.andymchugh.tag.plist

So now, when you write DayOne Journal entries you can mark up the tags.txt file that lives in your Dropbox. Value added, if you change this file anywhere, Dropbox will make sure it syncs up with all your other systems, so you can edit it and forget it pretty nicely as long as it’s not open-for-editing when your script fires off at 6am. That would be messy.

The first time you do it, you’ll notice your Dropbox churn for a long while and then all your other connected Dropboxes will churn as they sync up. Your iPhone and iPad will have huge downloads to do, but they’ll catch up well enough. As you create new DayOne Journal entries you can rest assured that your script will be doing keyword searching for you on your behalf and hooking up your tags to your DayOne Journal entries for you.

Just one more thing automated and out of the way. Hooray!

P.S. Backup your Journal, DIY. Be safe, be smart, learn how to use tar. man tar. Read it. Live it. tar is your delight and your savior. 🙂

EDIT: tags.sh needed a cd command first, otherwise it would just wander aimlessly. Sorry about that.