Percent Encode URL Not Behaving as Before in V. 9

I've been using Keyboard Maestro to create Things 3 templates successfully without issue for a while now. Unfortunately the changes to v.9 percent encoding seem to have broken my templates.

This is a sample of one of my templates: Book Project Template.kmmacros (26.0 KB)

It looks like Keyboard Maestro is now removing any non-numeric characters (e.g. "/" or ":") when running the percent encode action. Any ideas of how to fix this or is it just a bug?

1 Like

In the image below you can see at the bottom of the image that it takes the : and / characters and encodes them. Is this not what you want? It doesn't remove them, it encodes them.

image

I'll be honest with you, I've never used this action before, so you can take my advice with a grain of salt or just ignore me.

No, prior to the V.9 update, KBM left non-alphanumeric characters alone. V.9 introduced parsing them as a feature. I'm hoping there's a way to ignore symbols otherwise all my templates are broken.

For now, I've added several additional search and replace variable actions to un-encode the symbols.

You said you don't want it to translate non-alphanumerics. But that's the whole purpose of the action, I thought, to translate non-alphanumerics to URL friendly characters.

If you don't want it to translate ": and "/", what exactly do you want it to translate? I can probably find a solution for you if you tell me what you are trying to do.

Or we can just wait for someone on this website who's better than me at inferring what people want to do. I'm not one of the wizards here, I'm just an average guy.

That's a good temporary fix, I guess. Glad you got it working for you.

The original need was to parse the template and variables from natural language to work with the Things 3 URL scheme.

See Change Variable Syntax to Accommodate the Things 3 URL Scheme

That's great, several of the people on that thread are the wizards here, and I'm sure they'll have no trouble figuring out what you want the Percent Encode function to do here, since they helped you before.

KM9 did make a change to the Percent Encode URL

Adjusted Filter Percent Encode for URL to encode all non-alphanumeric characters.

According to HTML URL Encoding Reference

URL Encoding (Percent Encoding)

URLs can only be sent over the Internet using the ASCII character-set.

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

So the w3schools spec calls for encoding non-ASCII characters.
KM9 spec calls for encoding non-alphanumeric characters.

Here is perhaps a better spec:
Percent-encoding - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

I guess the question is what does @peternlewis mean by "non-alphanumeric characters"? Is that the same as "non-ASCII"?

@andreamocko, IAC, while there has been a change, is KM9 now providing the proper conversion from your POV?

1 Like

The intention of the action is to allow you to place fields within URLs.

So it encodes pretty much everything.

The passage quoted from W3 is only refering to the fact that URLs are intended to be ASII only so every non-ASCII character has to be encoded. It is not intended to imply that other characters might also have an impact on the URL and/or may need encoding.

Rather than construct your URL and then encode the whole thing, instead construct the fields of your URL, encode them and then combine them into the URL.

So rather than:

  • Set URL to “things:///add-project?title=Read %Variable%Title% by %Variable%Author%&deadline=21 days&area=Reading&to-dos=\nRead 10% of %Variable%Title% (%Calculate%Pages*.1%)\nRead 20% of %Variable%Title% (%Calculate%Pages*.2%)\n”
  • Percent Encode URL

Do something like:

  • Set Title to “Read %Variable%Title% by %Variable%Author%”
  • Percent Encode Title
  • Set Deadline to “21 days”
  • Percent Encode Deadline
  • Set ToDos to “\nRead 10% of %Variable%Title% (%Calculate%Pages*.1%)\nRead 20% of %Variable%Title% (%Calculate%Pages*.2%)\n”
  • Percent Encode ToDos
  • Set URL to “things:///add-project?title=%Variable%Title%&deadline=%Variable%Deadline%&area=Reading&to-dos=%Variable%ToDos%”

That way the correct characters will be encoded.

Otherwise, with your current technique, if the books have & or = or other characters in them you are going to run in to trouble.

2 Likes

According to Percent-encoding - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

Special characters needing encoding are: ':', '/', '?', '#', '[', ']', '@', '!', '$', '&', "'", '(', ')', '*', '+', ',', ';', '=', as well as '%' itself. ==Other characters don't need to be encoded==, though they could.

1 Like