Open URL Does Not Work with Hook:// Links?

I'm trying to open a number of files and applications with a single KM macro.

Some of these are websites, one is a crafts documents, and yet another one is a hook:// link (to a folder)
I know I can open the folder from KM directly, but I thought I'd simplify my macro building - since I already have all the hooks in a single document.
The open url action works for https://app.asana.com ..., or course. It also works for craftsdoc://open?xxxxxx, but it fails for the hook://file/xxxxx link. ( I get an error: Open URL failed with invalid url)

Hook seems to be properly registered as a url scheme provlder. If I copy paste the link into my browser adress bar, the target folder is opened.

Am I missing something in KM?

(cross posting to hook forum to figure out if it's a hook config issue ...:
https://discourse.hookproductivity.com/t/keyboard-maestro-open-url-action-fails-on-hook-links/2580)

Hey Paul,

Replace the URL in this macro with an appropriate Hooks URL and run it.

If it fails then the problem is likely not Keyboard Maestro.

-Chris


Open Hooks URL v1.00.kmmacros (5.5 KB)

Chris, thanks for this testing macro
putting :
hook://file/rOCm89XyK?p=cHJvamVjdHMvd3Jr&n=_DX02%20-%20Re%CC%81fe%CC%81rentiel%20de%20compe%CC%81tences
in place of the google url works perfectly ...

So at least now I know I can steal this script in my own macro to open the folder, but I guess we have a bug.

It may yet be a problem with Hook, though, because this is what my macro looks like:


As you can see, the Hook "open url" text is orange, while the Crafts one is black.
Maybe this denotes the fact that hook is not properly registered?

Hey Paul,

Sometimes URLs are encoded in a way Keyboard Maestro doesn't like.

You can fiddle with a filter and see

Run through the possibilities for URLs:

Filter.kmactions (421 B)

image

-Chris

Keyboard Maestro uses the system NSURL API to process URLs, and NSURL requires that the URL be formatted correctly. Incorrectly formatted URLs are not allowed and will not work.

Web browsers are often forgiving in the URLs they will accept, and will accept invalid URLs and translate them as best they can in to valid ones and process them after that translation. Keyboard Maestro will not - the URL must be valid.

Look at the URL that Keyboard Maestro is failing with and find the error in the URL and decide how you want to correct it.

1 Like

Got it: it's the accents! (I work mostly in French). The name of my folder is "Problème Bankable"
and Hook gives me this URL :

hook://file/tSfl7TRKH?p=RG9jdW1lbnRzL3Byb2plY3RzX2FyY2hpdmU=&n=proble%CC%80me%20bankable

The "è" should be %E8, not a bizarre %CC%80. If I correct the mistake in the URL I pass to KM, it works perfectly.

Thanks @peternlewis for pointing me in the right direction. I'll raise a bug in Hook.

1 Like

The difference will be the encoding. é is Unicode character 00E8. However, Unicode character 0300 (represented in UTF8 as CC 80) is a combining grave accent which means it adds the accent to the preceding character (e in this case).

They are both valid ways of representing é in text, but will not necessarily generate the same URL.

Note that in the Open URL action, if you want to have URLs with percent characters, you need to either turn off processing of text tokens in the Gear menu:

image

or encode the percent tokens (see Tokens).

3 Likes

Thanks for explaining this further.
As a recap - I can use hook generated links with accented characters if I select Process Noting in the gear menu , so I have a solution to my issue.

That said, your explanation raises a small question. Are both forms actually valid (since they are both proper unicode encodings)? And does the NSURL API requires the first form (unicode character 00E8) rather than the second (e + combining grave accent) ?

If you Process Nothing, so the % characters are left alone, then both e%CC%80 and %E8 are valid in the URL and NSURL will be happy with either, that is fine.

Whether they end up resulting in the same behaviour depends on what happens further down the track - in some instances they will result in the same path, but in others they might not.

2 Likes