Home

You’re Doing That Wrong is a journal of various successes and failures by Dan Sturm.

"Open on Which Mac" Shortcut v3

Two whole days ago, I posted an updated version of my Open on Mac Shortcut. When I post my hacky automation tools online, the absolute best possible response I can hope for is being corrected by someone much smarter than I am.

Like when I posted v1 of the shortcut and Jason Snell pointed out that I had inadvertently created a way for anyone with access to my Dropbox account to execute arbitrary code on my computer. Which is a pretty bad thing, to be honest. Luckily, he modified the shortcut and posted a much better version on Six Colors.

When I posted v2 of my shortcut on Tuesday, in the caption for the (very long) shortcut image, I wrote:

These If statements are terrible and ugly and there’s got to be a better way to do this, but I don't know what it is.

A few hours later, I received a lovely Twitter DM from Dr. Drang with the answer to my question.

To avoid the nested if statements, set up a dictionary with the Mac names as the keys and the file name prefixes as the values. Then assemble the file name by looking up from that dictionary after the Choose step.

— Dr. Drang, Famous Internet Snowman

 
 

The file name in the Destination Path of the Save File action is "Dictionary Value-URL-Current Date.txt. The shortcut is now much shorter, easier to understand, faster, and generally less bad.

Thanks, Doc.

"Open on Which Mac" Shortcut

A few weeks ago, I started a new job. Along with that job came a new iMac and Touch Bar MacBook Pro. Having doubled the number of computers in my life, I quickly found that my frequently-used Open on Mac iOS Shortcut was not working as expected.

While at work, attempting to open a webpage on my iMac would result in...nothing. When I got home, I found the pages open and waiting for me on my personal iMac.

Prior to the newly acquired computers, I had never given much thought to why webpages opened on my iMac rather than my MacBook Pro. I spent 98% of my time on the iMac and, since it was doing what I wanted it to do, there was no reason to ask why. I mostly assumed it was because the MacBook Pro was asleep and the iMac is always awake.

As it turns out, the real reason webpages always opened on my personal iMac is because it has the fastest internet connection (a wired fiber connection) and would therefore download the Dropbox file containing the URL before any other computers had the chance. Hazel would then do its thing, trash the file, and that was that.

It had become necessary to modify my iOS Shortcut, allowing me to specify on which computer I wanted to open the webpage. To accomplish that goal, I added a "Choose from List" action to the shortcut where I could pick which computer to use. Then, I added short prefixes to the filename that represented each computer.

 
 

The original text file containing the page URL was called "URL-Current Date.txt". The new file names are:

  • The Touch Bar: tbr-URL-Current Date.txt
  • The New iMac: niM-URL-Current Date.txt
  • My MacBook Pro: mbp-URL-Current Date.txt
  • My iMac: diM-URL-Current Date.txt

Add a couple of "If" statements to the shortcut and we're about done. Here's what the new, much longer shortcut looks like.

 

These If statements are terrible and ugly and there’s got to be a better way to do this, but I don't know what it is.

 

After finishing the shortcut, all that was left to do was add the prefixes to the name search field in the Hazel rules running on each computer and call it done.

P.S. Thank you, again, to Jason Snell for fixing my very unsafe, poorly conceived version 1.0.