Friday, February 27, 2015

iOS Automation - Importing Daily Notes to Day One as one entry

I've been trying to think of a way to use my diary app (Day One) a little more often. Usually I find that I either don't have time or I'm too tired to summarize the day before bed.

One idea that I had was to submit bite-sized entries as the day wore on. The shorter the update, the less of a burden it would be to write it and the more likely that an entry would happen.

I chose Day One as it's one of the most popular diary apps on iOS and it supports URL schemes (more on this later...) 

The approach that most people would take would be to launch the Day One app, open a new entry... add notes... save... repeat... This works but it would end up creating multiple entries for that day. I was hoping to only have one for the day. The other approach would be to open the relevant entry and keep adding to it but I was hoping to add a timestamp of when I added each comment. To do this, I would have to type in the date and time manually before adding each entry. Sounds like a job for automation!

So I turned to iOS automation using a combination of the following workflow-based applications:
  1. Launch Center Pro: This app is used as a central place to go to open other iOS apps and run various actions using URL schemes.
  2. Workflow: This app takes advantage of iOS 8's sharesheets, with the new ability to send data from one app to another.
  3. IF (formerly known as IFTTT): This app connects cloud based services with actions local to the phone. It is possible to connect IF with Launch Center Pro (LCP) and run LCP actions from IF.
  4. Drafts 4.0: This app is a note taking app that support actions. These actions support URL schemes and Javascript.
The goal was to prompt me for text, prepend a timestamp to it, add it to a text based note and at the end of the day, automatically send it to Day One and clear the note for the next day.

I must warn you that the following automated workflows may appear to be more convoluted than necessary. I'm sure that there are better ways to accomplish the same thing. This is how I chose to do it.

1) Appending a date and text to a Drafts 4.0 note


Launch Center Pro's action

This URL scheme will prompt you for text, send the text to Workflow, run the "Append to Drafts with Date" workflow and return to Launch Center Pro at the end.
  • launch://x-callback-url/clipboard?text=[prompt-return:Text]&x-success={{workflow://run-workflow?name=Append%20to%20Drafts%20With%20Date&x-source={{Launch Center Pro}}&x-success={{launch://}}}}

Workflow's "Append to Drafts With Date" workflow

Unfortunately, Launch Centre Pro doesn't have the capability to add a timestamp so I had to rely on Workflow instead. I hear that it may be possible with TextExpander but I chose to use this method instead.
  1. Get Clipboard
  2. Set Variable
    • Variable: Text
  3. Date
    • Use: Current Date
  4. Format Date
    • Date Format: Short
    • Time Format: Short
  5. Set Variable
    • Variable: Date
  6. Get Variable
    • Variable: Text
  7. Add to Variable
    • Variable: Date
  8. Combine Text
    • Separator: Custom
    • Custom:  :
  9. Add to Draft
    • Mode: Append
    • Draft UUID: ################
    • Edit in Drafts: Off
    • Run Action: Off
This will append an entry to a Drafts 4.0 note prefixed with "YYYY-MM-DD: "

The idea would be run the Launch Center Pro action whenever I wanted to record a bite-sized entry.

2) Scheduling a Task in iOS


It turns out that it is not possible to schedule a task to run at a specific time on its own. The best solution that I was able to come up with was to use IF (formerly known as IFTTT) to send a notification at a specific time which when opened would trigger the relevant action.

If you know of any other way of scheduling a task, please let me know.

3) Sending Content to Day One




First we start with an action from the IF app.

If the time of day is 11:15pm then run a Launch Center Pro action. In order to run LCP actions from IF, you need to set up a Launch Center Pro account and link it to IF.

IF's Recipe:


  • Trigger:
    • Every day at
    • Time: 11:15pm
  • Action:
    • Run custom URL
    • Which device? (select the relevant iOS device)
    • Custom URL:
      • workflow://x-callback-url/run-workflow?name=Send%20Content%20To%20Day%20One&x-source=((Launch Center Pro))&x-success=((launch://))
  • Notification:
    • Push to Day One?
  • Sound:
    • None

Workflow's "Send Content To Day One" workflow


  1. Get Contents of Draft
    • Draft UUID: ################
  2. Set Variable
    • Variable: Content
  3. Get Variable
    • Variable: Content
  4. Count
    • Count: Characters
  5. Calculate
    • Operation: /   (divided by)
    • Operand: 3.142
  6. If
    • Input: Contains
    • Value: .
  7. Open Draft
    • Draft UUID: ##############
    • Edit in Drafts: Off
    • Run Action: On
    • Action: Export To Day One
    • Key: (Leave blank)
    • After Success: Nothing
  8. Otherwise
    • Vibrate Device
  9. End If

Drafts 4.0 "Export To Day One" Action


  • Steps: 
    • 1 step: URL
      • Description: Open a URL
      • URL Template: 
        • dayone://post?entry=[[draft]]
  • Action Groups:
    • 0 groups
  • Description:
    • Send draft to Day One as a journal entry
  • Advanced:
    • Confirm before running: Off
    • After Success: Default
    • Log level: Errors

4) Clearing the Drafts Note after Content Has Been Sent To Day One



Unfortunately, it's not possible to include this function in the previous step because Day One does not support x-callback-url URL schemes. These allow you to launch another application, perform and function then then return to the original or another application. Without it, the previous action will open Day One and add the content to a diary entry. The edit window in Day One would remain visible instead of returning to the application that launched the initial request.

If the time of day is 11:30pm then run a Launch Center Pro action.

IF's Recipe:


  • Trigger:
    • Every day at
    • Time: 11:30pm
  • Action:
    • Run custom URL
    • Which device? (select the relevant iOS device)
    • Custom URL:
      • workflow://x-callback-url/run-workflow?name=Remove%20Drafts%20Content&x-source=((Launch Center Pro))&x-success=((launch://))
  • Notification:
    • Remove Drafts Content?
  • Sound:
    • None

Workflow's "Send Content To Day One" workflow


  1. Get Contents of Draft
    • Draft UUID: ################
  2. Set Variable
    • Variable: Content
  3. Copy To Clipboard
  4. Get Variable
    • Variable: Content
  5. Count
    • Count: Characters
  6. Calculate
    • Operation: /   (divided by)
    • Operand: 3.142
  7. If
    • Input: Contains
    • Value: .
  8. Open Draft
    • Draft UUID: ##############
    • Edit in Drafts: Off
    • Run Action: On
    • Action: Remove All Text
    • Key: (Leave blank)
    • After Success: Nothing
  9. Otherwise
    • Vibrate Device
  10. End If

Drafts 4.0 "Remove All Text" Action


  • Steps: 
    • 1 step: Script
      • Description: Run JavaScript
      • Script: 
        • var sel = draft.content;
          draft.content = "";
          commit(draft);
  • Action Groups:
    • 0 groups
  • Description:
    • Remove all lines from your Draft
  • Advanced:
    • Confirm before running: Off
    • After Success: Default
    • Log level: Errors

Conclusion


Although it is a little convoluted, this workflow ends up working quite well for me.

Some of the things that I learned during this experiment:

  1. You cannot schedule an automated tasks on a non-jailbroken iPhone without manual intervention.
  2. To schedule an automated task, you will need to use IF (aka IFTTT) and Launch Center Pro. A Launch Center Connect account is required (no additional cost and initiated within the LCP app itself.)
  3. It is possible to add a timestamp and delimiter using Workflow. TextExpander also works apparently but I haven't tried it out.
  4. Day One doesn't support x-callback-url URL schemes. This means that you cannot chain actions together. Without support for it, the action sequence will always end at Day One. I have contacted their support team and have put in an request for this.
  5. IF recipes are typically triggered a few minutes after I specify.
  6. You can only modify text using Javascript in Draft 4.0. The built in options in Workflow and LCP don't allow you to modify content, only add to it.
  7. It is possible to check for content in a variable using Workflow but the process is not very straight-forward. 
That's all for now. Let me know if you have any better ways of going about all of this.


Wednesday, February 4, 2015

The Weightloss Workaround

I've discovered a secret... a way to magically lose a pound or two within 15 minutes.



All it takes is to have a hot shower. It doesn't always work and may be more prevalent in the winter when it's cold in the bathroom but I have repeatedly weighed myself before and after a hot shower and typically lose 1 - 2 pounds.

Your mass doesn't really change from taking a shower. It may even increase due to absorbing water but your weight will generally go down. This is because heat rises causing an updraft around your body, tricking the scale into reducing your weight.



If you track your weight daily, this would be the best time to weigh yourself. :)



Note that if the temperature in the room is close to your body temperature after the hot shower, you may not notice much of a difference but give it a shot and start feeling ten times better everyday!


Other weight-loss workaround tips:
  1. Always weigh yourself right after you get out of bed in the morning. This seems to be when you weigh the least.
  2. Go to the bathroom before you weigh yourself. This sometimes helps.
  3. Don't wear any clothes when weighing yourself.
  4. Weigh yourself before eating any food.
  5. Have your hot shower right after you wake up and then weigh yourself.