Pasting a complex URL with variables included doesn't seem to be working

Hello,
I've been using Keyboard Maestro for a long time and this is the first time I'm asking for help.

I have a complex URL which I want to paste into the Terminal app with KM variables that insert current GMT date and other parameters. I've gotten it all to work with most of the URLs I need to use, but this particular one has % signs that KM seems to mess up. I'm not sure if it's a bug or I'm not handling the URL correctly.

Here's the curl command and URL I want to paste into Terminal:

curl -O 'https://nomads.ncep.noaa.gov/cgi-bin/filter_nam_conusnest.pl?file=nam.t00z.conusnest.hiresf[00-%Variable%Duration%].tm00.grib2&lev_entire_atmosphere_\(considered_as_a_single_layer\)=on&var_TCDC=on&subregion=&leftlon=-87&rightlon=-65&toplat=47&bottomlat=30&dir=%2Fnam.%ICUDateTimeFor%NOW()+ (360*60) %yyyyMMdd%'

Please note that [00-%Variable%Duration%] is one KM variable that I fill in with a prompt from KM.
and note that %ICUDateTimeFor%NOW()+ (360*60) %yyyyMMdd% is another KM variable that inserts the current date (corrected for GMT)

--> The part of the URL that is messing things up is the middle section of the URL, specifically this string- %5C%28considered_as_a_single_layer%5C%29

The % symbols in this section of the URL are are in the actual URL. (I think they are Unicode changes for () symbols. I think KM is having trouble with it.)

Anyhow, Keyboard Maestro doesn't seem to like this part of the URL with the other KM variables embedded in the complete URL. I've tried the filters and multiple attempts to break the URL into pieces, but KM translates the entire string with errors in this section

When I've tried to debug it, this is what KM pastes as the URL:

curl -O 'https://nomads.ncep.noaa.gov/cgi-bin/filter_nam_conusnest.pl?file=nam.t00z.conusnest.hiresf[00-24].tm00.grib2&lev_entire_atmosphere_\28considered_as_a_single_layer\29=on&var_TCDC=on&subregion=&leftlon=-87&rightlon=-65&toplat=47&bottomlat=30&dir=%2Fnam.20190415'

Please note that the it works properly EXCEPT for this part of the URL:
%5C%28considered_as_a_single_layer%5C%29.

KM converts that part of the URL string incorrectly to:
\28considered_as_a_single_layer\29

Again, I've tried the various filters, escape characters and trying to store the messed up section in its own variable, but to no avail.

I'm not sure if the particular string is something that is internally problematic for KM because of the way it used %signs to insert token variables.

Any help on how to handle that part of the URL would be greatly appreciated.

Thanks.
Glen

% means something in text tokens.

And % means something in URLs.

So for example:

%5C%28considered_as_a_single_layer%5C%29

To a URL, that means character 5C, character 28 “considered_as_a_single_layer”, character 5C, character 28.

But to Keyboard Maestro it means character 5C, “28considered_as_a_single_layer” character 5C “29”

You can turn on token processing in Keyboard Maestro which will then leave the % characters alone, but then you cannot insert the variable.

So you have two choices:

  1. Double all the percent characters in the Keyboard Maestro text token field that you want Keyboard Maestro to ignore. That is, every percent character in the URL that is not part of a Keyboard Maestro text token should be replaced by “%%”.

  2. Separate the URL into parts, each part being either plain text or a text token:

    1. https://nomads.ncep.noaa.gov/cgi-bin/filter_nam_conusnest.pl?file=nam.t00z.conusnest.hiresf[00-
    2. %Variable%Duration%
    3. ].tm00.grib2&lev_entire_atmosphere_\(considered_as_a_single_layer\)=on&var_TCDC=on&subregion=&leftlon=-87&rightlon=-65&toplat=47&bottomlat=30&dir=%2Fnam.
    4. %ICUDateTimeFor%NOW()+ (360*60) %yyyyMMdd%

Set each of the plain text (1 and 3) into variables URL1, URL2, with the token processing turned off.

Then you can combine them all:

  • Set Variable to Text “%Variable%URL1%%Variable%Duration%%Variable%URL2%%ICUDateTimeFor%NOW()+ (360*60) %yyyyMMdd%”

Or a third option is you can set a variable with token processing turned off, but holding placeholders in the text, eg:

  • Set variable URL to “https://nomads.ncep.noaa.gov/cgi-bin/filter_nam_conusnest.pl?file=nam.t00z.conusnest.hiresf[00-KMDURATION].tm00.grib2&lev_entire_atmosphere_\(considered_as_a_single_layer\)=on&var_TCDC=on&subregion=&leftlon=-87&rightlon=-65&toplat=47&bottomlat=30&dir=%2Fnam.KMNOW”

Then use Search and Replace to replace the KMDURATION and KMNOW with the desired values.

BTW, make sure your tokens are properly URL encoded, perhaps with the appropriate Filter.

2 Likes

Thank you, Peter, for
explaining the issue and providing two solutions to the
problem! I will look at both solution and which see which works
easier for me. And thanks again for a truly invaluable software
product for the Mac. I can't imagine not having it.

Glen