569: Contextual Computing

So, start with the file path:

/Users/chris/Documents/Test File.txt

The problem here is that URLs can’t have spaces in them. When I paste it into Things, it assumes that the space is the end of the URL and tries to link to a file named ‘Test’ instead of ‘Test File.txt’:

Screen Shot 2021-01-07 at 11.24.20 AM

We could just never use spaces in our file paths, but the Mac has supported spaces in file and folder names since time immemorial. Instead, we can get around this by URL encoding the path, replacing the space with %20. You could do this manually, but that would be a pain and we’d also have to replace any other characters that aren’t valid in a URL. Instead, we can use URL encoding software to make all the necessary substitutions for us. If you want to play around with it, there are websites that will URL encode text for you. If this is something you want to make part of your workflow you probably want to script it (this can be done using the Filter action in Keyboard Maestro and setting it to “Percent Encode for URL”).

This gives us:
%2FUsers%2Fchris%2FDocuments%2FTest%20File%2Etxt

In order to make Things or other programs that automatically convert URLs to links recognize this as a URL we need to put file:// in front of the URL-encoded path (just like URLs for websites have “http://” at the front).

file://%2FUsers%2Fchris%2FDocuments%2FTest%20File%2Etxt

Now when I paste this into Things it recognizes the whole string as a URL and doesn’t stop at the space:

Note that when I hover over the link, Things automatically decodes the URL turning %2F into a slash and %20 into a space:

If I click the link it will open my Documents folder in a Finder window with Test File.txt selected. ⌘-O will open it in whatever the default app is for that file type.

3 Likes

Great episode guys!

@MacSparky David, could you explain how your “minimize all windows” Keyboard Maestro macro works or what actions it uses? I can’t find a way to minimize all in the “manipulate a window” action. I was hoping it was a downloadable macro in the Keyboard Maestro Field Guide but couldn’t find it.

Contextual Computing is an amazing concept, I’m looking forward to more development of this!

@ismh I am now doing the same. Once I realized that I could import markdown files and could bulk export any notes from Craft in four formats if and when needed, I made Craft my default note taking application. It is also working well as a PKM app. While I like Obsidian, I’m finding Craft more flexible and better suited to my needs. Very impressed so far and the developer, Viktor, has been helpful and responsive.

There is a minimize all command but tactically use the close specific app command. :slight_smile:

1 Like

Fascinating episode as always. Just a quick note on how I’m using MIDI triggers with BetterTouchTool, Keyboard Maestro, and HomeKit on my Mac.

A few of the knobs on my M-Audio keyboard typically go unused, so I’ve assigned BTT “Value Changed” triggers - which run AppleScript to invoke Keyboard Maestro to send hotkeys to the “Homie” (Menubar app) to control the brightness of the left and right desk lamps.

Homie (or HomeControl) allows you to assign individual hotkeys to Scenes - though HomeControl throws an alert if you send keystrokes faster than it can respond.

@MacSparky said he uses 1Password to generate fake UUIDs for notes.

I need to make UUIDs all the time for work. Fortunately Mac OS X ships with /usr/bin/uuidgen which can help with that.

To turbo charge this, just add a TextExpander snippet, and set the content to Shell Script:

#!/bin/bash
/user/bin/uuidgen

Saves me a lot of time!

12 Likes

Thanks @knowuh. I didn’t know about that. New toy!

2 Likes

Very cool. I didn’t know about this either. Inspired by your Text Expander snippet, I made an Alfred Workflow to do the same thing. I put it here: https://github.com/ethanweed/Alfred-make-UUID

1 Like

@Aaron_Antcliff I’d love to see your workflow on this - I’m still trying to get my head around just how to surface these connections effectively.

I use a TextExpander snipped to make Zettelkasten numbers as unique ids - YYYYMMDDHHMMSS

3 Likes

After some back and forth (since Catalina’s Notes AppleScript brook), Hook [generates URLs for notes based on their date-time stamps]( Using Hook with Apple Notes – Hook). Apple doesn’t directly expose the Notes URLs, but I am hopeful they will follow the trend towards exposing links in a helpful manner.

1 Like

oops, I hadn’t read down so far when I posted my comments above on same.

1 Like

well, as we’re on the topic of hook://file// URLs, another distinctive feature of course is that hook://file// can be shared with others (e.g., in Git, SVN, Dropbox, etc.). You can even email the file to someone along with a link. They can move the file around and still use the link. Those cases require the last part of the pathname to be the same. We tweak the algorithms over time to optimize robustness. Hook also supports deep linking of PDFs, so you can point deeply into the PDF (interchangeably with Skim, PDFpenPro and soon Adobe Acrobat). etc.

Same here, not sure what difference there is between the uuid scripting option, and generating these date specific ones, other than that you can sort the latter?

I had to delete the path on the second line to make this work on my M1 MacBook Pro. Just FYI and for anyone else having trouble.

I guess the swift way will also work
can someone confirm?

#!/usr/bin/swift

import Foundation

print(UUID().uuidString)
1 Like

(Off topic perhaps but am I picking up the right drift - that Swift can be used as an inline scripting language?)

Yes. One of the reasons that I would love to know swift. You can use it as a 'shell script’ as long as you start with the proper shebang, as shown above:

#!/usr/bin/swift

1 Like

Right. It was the “Showing Of The Shebang” (movie title?) :slight_smile: that got me asking. My assumption is that something (not sure what exactly) interprets or compiles the script. Might not run fast, of course.

This is a great idea and a useful Alfred workflow. Unfortunately, when I click on the supplied GitHub link a 404 error is returned. Any thoughts? Thanks again for sharing.