Put Your Mac to Sleep with iOS Drafts

Occasionally, I have sensitive things on my Mac’s screen and occasionally I leave an office, or conference room, or courtroom and forget to shut the lid on that Mac. While I’ve got my Mac set to lock itself down after a few minutes, I thought it would be nice to have a way to force the issue. Mac Power User listener Mariusz wrote me about Polish Mac Geek Milosz Bolechowski who pulls this off with Drafts, a Dropbox File, and Hazel. I thought it was pretty clever so I duplicated it tonight.

This is how it works:

  1. I type “MB sleep” in Drafts and save it to the standard Drafts folder on Dropbox. (In my case it is located at Dropbox/Apps/Drafts.) I use “MB sleep” because I’m going to add a second one for putting the iMac to sleep.

  2. Point Hazel at the Drafts folder and tell it to look for a file that contains the terms “MB sleep”

  3. When Hazel sees the file, it deletes it and runs an AppleScript to put the Mac to sleep.

This is a really simple script.

tell application “Finder”

sleep

end tell

Once you set this up, open Drafts and type “MB sleep” and save it to Dropbox. Within a few seconds, your Mac goes safely to sleep.

Extra Credit

Milosz had another great idea of using a URL scheme to further automate this. If you want to take it a step further, set up a URL scheme in Launch Center Pro as follows:

drafts://x-callback-url/create?text=MB%20sleep

Then when you tap the button in Launch Center Pro, it opens Drafts and fills in the text “MB sleep” for you. You just need to send it to Dropbox for the Magic to happen. The below screenshot gallery gives you the details.

Update

Extra Extra Credit

On Twitter, @Eiscik points out the following Launch Center Pro action performs the Dropbox upload for you with no further taps.

drafts://x-callback-url/create?text=MB%20sleep&action=Save%20to%20Dropbox

Create OmniFocus Tasks with AppleScript

Sometimes efficiency becomes the enemy. Because I’m now a believer in automating document filing via Hazel and OCR, I sometimes get myself in trouble. A case in point is my life insurance bill. It arrives every quarter. I used to scan it and then name it in my Action folder with a TextExpander snippet, which resulted in it getting sent off to a nested folder somewhere. At the same time I’d record an OmniFocus quick entry to pay the bill. It was all second nature.
These days, I use a Hazel rule that looks at the contents of this invoice and names it and files it without me having to trouble to rename the file manually. Put simply, once I scan it, I never see it again unless I go looking for it. The problem is I keep forgetting to create the OmniFocus entry to pay the bill. That’s bad. (Especially if I get hit by a bus, which would only add one more problem to cascading badness.) We can’t have that.

I decided to create an AppleScript that automatically creates an OmniFocus task when this Hazel rule triggers. After a lot of head scratching, trial and error, and even some help from friends at the Omni Group and Ben Waldie (my AppleScript Sensei), I’ve cobbled one together. Here is a screenshot and the AppleScript code.


-- Lovingly crafted by David Sparks, The Omni Group, and Ben Waldie -- macsparky.com

set theDate to current date
set theTask to "Pay Life Insurance"
set theNote to "Lovingly Scanned by your Mac on " & (theDate as string)

tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "Tech"
set theProject to first flattened project where its name = "Finance"
tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}
end tell
end tell

To test the rule, open AppleScript Editor and copy it in. You need to change the context and project names to something that is in your OmniFocus library. Once you trigger it, AppleScript will create a new task in the designated project with the designated context. The task also gets named and the Note field will include the text “Scanned on {today’s date}”. This just happens. Don’t believe me? Go look in your OmniFocus project afterward.

I use this script directly in Hazel. Specifically, when I’ve got a scan that requires future action, I add an AppleScript Hazel action at the end to run this script. After Hazel gets done naming and filing my document, it creates a handy OmniFocus task. Below is my life insurance Hazel rule screenshot to demonstrate.


I’ve modified several versions of the script to handle the variety of documents I scan and OCR that require an automatic OmniFocus action. Creating an OmniFocus task with a script is damn useful. You could use this in a lot of contexts outside of document filing. You’re welcome.

Below is a download link for the Hazel rule. Go nuts.

Download Sample Hazel Rule

Hazel Update

 

One of my very favorite Mac utilities, Noodlesoft’s Hazel released an update this week with several interesting feature addtions. You can now add sequential numbers to your rules and reference a source folder allowing you to mirror folder structures when moving and copying files. The update is free to registered users and a new license for Hazel is $22. You can learn more about Hazel at my review here and one of my favorite Hazel workflows here.