In the Finder, if I use the “Connect to Server” dialog box like this:
smb://tv.m.h/TV|9/00/56/005674/
the served folder “005674” mounts on my desktop; this also works fine with the afp:// protocol. This is exactly what I want to have happen, and what I would like to script with Keyboard Maestro.
For initial testing, I tried the “Open URL” action with literal strings:
If I use the Open URL action in Keyboard Maestro with the string I quoted above as literal text, Open URL is rendered in bright red, presumably implying that it wants me to percent-encode the URL. Attempting to run that one-step macro sends my web browser to keyboardmaestro.com.
If I instead percent-encode everything (except the protocol and the colon slash slash), Keyboard Maestro gives me an orange Open URL, which I read means that it’s invalid now but KM thinks it might be OK when I run the macro. If I do run it, the one-step macro quits with the error, “Open URL failed with an invalid URL: smb://tv%2Em%2Eh%2FTV%7C9%2F00%2F56%2F005674…”. I get a pretty similar error if I try this in the Finder: “There was a problem connecting to the server ‘tv.m.h/TV|9/00/56/005674/. The server may not exist or it is unavailable at this time. Check the server name or IP address, check your network connection, and then try again.”
If I try percent-encoding everything including the protocol, Keyboard Maestro again gives me an orange Open URL. And if I run it, it quits again, with nearly the same error as above: “Open URL failed with an invalid URL: smb%3A%2F%2Ftv%2Em%2Eh%2FTV%7C9%2F00%2F56%2F00”. If I try this in the Finder, I receive the exact same error message as with a non-percent-encoded protocol.
“Well,” I thought, “perhaps it works differently for some reason if I use variables.” So, I tried that.
As with #1 above, I used smb://tv.m.h/TV|9/00/56/005674/ for my variable T90__Program_path’s value, and then attempt to use the variable %Variable%T90__Program_path% as the argument for the Open URL action: the macro failed with the error “Open URL failed with invalid URL ‘Variable%T90__Program_path’ Macro ‘Trying’”.
As with #2 above, I then used smb://tv%2Em%2Eh%2FTV%7C9%2F00%2F56%2F005674%2F as the variable’s value. This did not cause the macro to exit! But I got the same Finder error as with #2 above.
As with #3 above, I then used smb%3A%2F%2Ftv%2Em%2Eh%2FTV%7C9%2F00%2F56%2F005674%2F as the variable’s value. Absolutely nothing happens at all when I attempt to run this step.
I can’t think of anything else to try. No percent-encoded variant works in the Finder; it wants just straight text. Keyboard Meastro seems to insist on percent-encoded URLs — but they don’t work in the Finder.
That is because the URL is invalid. Non-ASCII and various other characters must be encoded to make a valid URL. Specifically in this case the | symbol is invalid in the URL. A valid URL is:
smb://tv.m.h/TV%7C9/00/56/005674/
The Percent Encode for URL filter will lead you in the right direction, but it is for encoding individual fields in a URL, not the entire URL. You can use it to encode the | to determine that %7C is the proper encoding for the character, but you cannot encode the whole thing, the :// and . and / has meanings and they are not meant to be encoded in this context.
The | is, I believe, the only character that needs encoding in that URL.
This is what comes of too many sleepless nights. Yes, of course both the . and the / characters must be non-encoded — though I’m sure back in early internet days I saw encoded %2F get treated as / (“create no bad data; deal with all the bad data you receive”).
BTW, FWIW, | is old-school ASCII: 007C; there must be some other determinant as to whether a character should be URL-encoded or not.
Thanks for your patient help, esp. during what’s probably your busiest week of the year!