569: Contextual Computing

There’s a way to fetch the already encoded file:// link via Finder’s AppleScript. I’ve set mine to auto expand wherever I type ;flink (via Keyboard Maestro typed string trigger).

tell application "Finder"
	set theItem to the first item of (get selection)
	set theURL to the URL of theItem
	return theURL
end tell

Here’s how it looks like in Keyboard Maestro

Got that idea from @MacSparky’s TextExpander tip for executing AppleScripts via text expansion. From there, I’ve learned some AppleScript and looked for ways to fetch links to the current item in Finder, Things, Obsidian, Safari’s frontomost tab URL, etc.

Some are really wonky, but the vast majority are very straightforward requiring almost not intervention on the scripts whatsoever. So here are a few more for anyone who’s looking for something like this and looking for inspiration.

If you want to use Keyboard Maestro, just copy the instructions from the screenshot and the scripts bellow into the Execute AppleScript textbox. I also recommend using the same ;Xlink grammar to help memorizing them (for me, Things is a ;tlink, Safari a ;saflink, Obsidian an olink, Evernote a ;elink, etc.)

I know Hook has a way to do this (invoking it with the source item open and hitting ⌘+C to get the link and then pasting it into the target app), but I find typing these text strings to be faster and not depending on a third-party app to tie them together.

Things

tell application "Things3"
	set lista to selected to dos
	set theItem to the first item of lista
	set idItem to id of the first item of theItem
	set linkThings to "things:///show?id=" & idItem
	return linkThings
end tell

Safari

For the plain URL:

tell application "Safari"
	tell window 1
		set safLink to URL of current tab
	end tell
end tell
return safLink

If you rather have a markdown input, I use this:

tell application "Safari"
	tell window 1
		set safLink to URL of current tab
		set titulo to name of current tab
	end tell
end tell
return "[" & titulo & "]" & "(" & safLink & ")"

Evernote

tell application "Evernote Legacy"
	set lista to selection
	set nota to first item of lista
	set titulo to title of nota
	set elink to note link of nota
	return titulo & linefeed & elink
end tell
4 Likes

What I forgot to mention is that the Hook links actually follow the file after a move and/or rename. I thought that wasn’t possible with AppleScript. I’ll need to dig deeper on this.

8 Likes

I expect Keyboard Maestro to be around until Apple makes it impossible to use on the Mac or its developer dies.

I hope neither of those things happen anytime soon. Only one is inevitable but hopefully a long way in the future.

2 Likes

Wasn’t David talking about how frustrated he was that Finder didn’t have URL links?

Anyways, I found and adapted an AppleScript for just that issue. It takes the currently selected file, gets the file path, and then converts the file path into a Finder URL scheme, then copes the URL to my clipboard.

After Catalina, macOS finder added quick actions in the preview pane of finder. So basically, if I want a URL for a file in finder, I just click the button in the preview pane and then I already have the URL in my clipboard.

I would share the AppleScript with you guys here, but I can’t seem to find it. Sorry.

2 Likes

You’re right in that both the AppleScript and the Keyboard Maestro Macro mentioned by @ChrisUpchurch won’t update if the file moves or renames.

What you seem to have missed on show was the fact that Finder can produce these links (even if they’re static) with some workarounds.

Those could be either with @ChrisUpchurch Keyborard Maestro Macro, a text expansion AppleScript or even the Quick Action suggested by @DandyLyons (btw, that AppleScript I’ve shared could be used for creating that Quick action by changing the return command to set the clipboard to).

3 Likes

@MacSparky @ismh, since both of you mentioned using and experimenting with Craft, I would love to hear a more in-depth assessment. I’ve only briefly looked at it. I’m using Drafts, Ulysses, Obsidian and DEVONthink extensively. And due to periodic syncing problems with Apple Notes, I seldom use it as I posted here.

Given that both of you also use DT, Drafts, and Ulysses, how does Craft complement your workflow? Why is Craft needed/helpful given the other apps you use? I for one would love to hear more about this in an upcoming episode.

Thanks again for the excellent podcast and forum.

3 Likes

I’ve used Craft as a note repository for my work notes, instead of them being mixed in with personal stuff in Apple Notes.

I would be very interested, and perhaps others would as well, how you differentiate your use of something like Devonthink versus Craft. Right now I have been storing all of my work related notes in DEVONthink along with the necessary research and resource documents. I’m trying to determine what utility Craft would add to my workflow equation. :slight_smile: this may be too complex for the form but perhaps it could be addressed by you and or David in a subsequent podcast.

3 Likes

Hook has become a surprise for me in terms of usefulness, I didn’t give it enough credit when I tried it out when it was first released, but now it’s become indispensable for certain project files.

2 Likes

For my uses, DEVONthink is 100% research materials for my content creation work. Books, magazines, whitepapers, etc.

Notes in Craft are just for me, and cover all sorts of things from travel docs (haha), server configuration notes, reminders of certain Logic settings, etc.

3 Likes

@MacSparky , I am a music teacher and arranger, and I have an Alesis 49-key MIDI controller on my desk in my home office that is filled with Keyboard Maestro shortcuts. Almost all of my KM shortcuts are assigned to keys on the MIDI Keyboard, from window management to launching contextual workspaces. It is basically like a 49-key StreamDeck from the point of launching macros.

I have all of the macros triggered from a single macro group so whenever I dive into my music writing software or need to use the keyboard, I can just use the F19 key on my keyboard to toggle on and off the macro group, so I can use the keyboard to input or play music.

I have the macros in the “Alesis Controller” Macro Group, use “If application is at front” so each key can be a different macro depending on the app.

I definitely agree @Justin_H about the nanoPad and nanoKey. I have on of those at my desk at work and have a few macros on that for when I don’t have my home setup and just my laptop. At $49 the nanoPad would function great as a “StreamDeck” like product (without the programmable button images, tho)

2 Likes

Doesn’t DT and Drafts have the ability to create a URL with a UUID? Wouldn’t a URL with a UUID, still work even if the file is moved/renamed.

Both Devonthink and Drafts prefer using UUID rather than paths (as Finder does for file:// links), so they don’t break when moving.

Others, like Obsidian and Finder, prefer using absolute/relative paths to a file. Those will break if the file is moved or renamed because the previous path in the link will no longer point to the corresponding file.

A workaround is to use a third party app (such as Hook or Devonthink) that has the ability to create and monitor a database of files and use its own link to refer to the file on the system. That will require for the indexing part of the app to be running when file is moved or renamed.

3 Likes

Do you compartmentalize in such a way due to personal preference (one app for one area of work) or is there a specific practical reason which makes Craft/DT more suitable for one of the two use cases and vice versa?

1 Like

Two thoughts:

  1. Conflict palette is great.
  2. The real problem for me with Contextual Computing is deciding what the contexts are and what goes in them. For me, these are leaky containers.
1 Like

Personal preference, but the Markdown support is more handy for work stuff, too.

1 Like

Regarding Notes support for Hook: This was bugging me, so I looked into it further. Short version: Hook supports Notes in Mavericks and Big Sur, and has partial support for Notes in Catalina. More information:

Interestingly, Hook uses the note creation date and time as a unique identifier for each note, which is very clever indeed!

Awesome tip, Chris! However, you lost me on URL encoding the pathname before putting file:// in front of it. How do you do that?

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!