Monday, 24 February 2014

Creating DayOne entries from IFTTT recipes using DropBox and Hazel

Why?

So IFTTT can automatically add DayOne entries for:
  • Photos taken.
  • Places we go.
  • Weather forecasts.
  • News snippets from RSS feeds.
  • Pretty much anything you can imagine using IFTTT.


How is it going to work?
  • We're going to give IFTTT permission to access DropBox so it can write files.
  • We're going to write a hazel script to look for the IFTT files and create DayOne entries. 


What do we need?


1. Create a "DayOneInbox" folder

Create a DayOneInbox folder in DropBox, this is where IFTTT will drop it's files.

2. Create Hazel rules for "DayOneInbox"



Create a shell script rule for text files:


FILE="$1"
DATE=`stat -t "__%m/%d/%Y %l:%M%p__" "$FILE" | sed -e 's/.*\"__//g' -e 's/__\".*//g' | tr '[:lower:]' '[:upper:]'`
cat "$FILE" | /usr/local/bin/dayone -d="$DATE" new

Create a shell script rule for images:


FILE="$1"
DATE=`stat -t "__%m/%d/%Y %l:%M%p__" "$FILE" | sed -e 's/.*\"__//g' -e 's/__\".*//g' | tr '[:lower:]' '[:upper:]'`
/usr/local/bin/dayone -d="$DATE" -p="$FILE" new

You can test this already by dropping images or text files into **DayOneInbox**. Hazel should pick them almost instantly and create DayOne entries.

The beauty of the the rules above is that even if you don't turn your Mac on for a few days, they should be added to DayOne on their creation date.

3. Create IFTTT Recipes

Activate the DropBox Channel in IFTTT. Your IFTTT recipes (whatever they are) should leave text or image files in your DayOneInbox folder.

14 comments:

  1. Hmm. For some reason files that are created in DropBox when the mac is offline they all end up having todays date in DayOne.

    Files with dates in the past that I COPY into DropBox work fine.

    ReplyDelete
  2. What does one do with the dayone CLI utils after downloading them? Install them ... use them ... how?

    ReplyDelete
    Replies
    1. The DayOne CLI tools need to be installed so that the Hazel bash scripts actions above can use them.

      The last line of each calls /usr/local/bin/dayone (from the CLI tools) to create the entry, either an image or a text one, Hazel itself determines the type with the "if kind is..." test.

      Delete
  3. This looks pretty nifty, will try it out. Thanks for the tip!

    ReplyDelete
  4. Did you also have a look at similar tools like Sifttter-Redu (http://github.com/bachya/Sifttter-Redux) or Slogger (http://brettterpstra.com/projects/slogger/)? This saves you from using Hazel and you don't even need to have DayOne installed on the computer these tools are running.

    ReplyDelete
    Replies
    1. Sounds interesting, might take a look - thanks.

      Delete
  5. I like this workflow as an addition to SIFTTTER and Slogger. Another step towards journalling my life. Thanks for this workflow!

    ReplyDelete
  6. UPDATE: I've tweaked the scripts (2nd line only) to fix an issue where if the file created by IFTTT had '__' in it then date got scrambled by sed and DayOne imported the file with todays date at 12am.

    Just don't use quotes in the filename mmmkay.

    ReplyDelete
  7. I tried this, and while they both make an entry, the image entry is blank, and the text entry is gibberish. Any idea why?

    ReplyDelete
    Replies
    1. Odd - if you're getting entries created with the right timestamp then hazel and the scripts are working. There must be an issue with the content of the file.

      Have you got the file types back to front - i.e. creating a text entry with an image or vice versa?

      Delete
  8. I'm getting shell script errors. Could it be because I have 2 profiles on my computer, my main account and a guest account?
    I know very little about scripting and was trying to figure it out.

    ReplyDelete
    Replies
    1. I found "non-successful status code: 126" when I finally found the text log file....

      https://plus.google.com/105362876849493580740/posts/j6WGvBe6jxa

      Delete
  9. This comment has been removed by the author.

    ReplyDelete