Task: given a base64 encoded string, decode and display it via keyboard shortcut.
Given test string, set to variable b64inputString via earlier macro step: UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADMAMAAwADAAYAAiACIA
the decoded text should be: Start "`"http://localhost:3000`""
Methods tried:
run shell script using bash, display results in a window:
/usr/bin/base64 -D <<< $KMVAR_b64inputString
result: S^@t^@a^@r^@t^@ etc etc
Copying this from the window results in the unprintable characters being changed, but I really need a display without all of this garbage in it. Let's try large:
run shell script using bash, display results large:
/usr/bin/base64 -D <<< $KMVAR_b64inputString
result: one (very) large S
hmmm. let's try in sh and bash directly: bash3.2$ /usr/bin/base64 -D <<< UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADMAMAAwADAAYAAiACIA
result: Start "`"http://localhost:3000`""
hrm, okay, so something is maybe happening with how KM is handing the characters. This definitely isn't "usual" base64, but base64 -D is still able to handle it... let's try python!
run shell script using python3.9, display results in window: /usr/local/bin/python3 -c 'import base64; import os; INPUT = os.environ.get("KMVAR_b64inputString"); print (base64.b64decode(INPUT).decode("ascii"))'
result: S^@t^@a^@r^@t^@ etc etc
okay, how about shell script, python3.9, display results large:
result: see result 2 (one very large 'S')
What am I doing wrong, what am I missing? (UTF-8 vs ASCII decode doesn't matter in python either, fwiw). Setting the system clipboard to the output just results in S. Is this just weirdness in KM's text handling? am I returning the wrong data? Not properly formatting it in the script somehow?
Follow up, for anyone having future trouble like this: disabling the "Trim Results" text results in a semi-working, expected outcome, but only if I "display results large", and only in python. Saving to a variable so I can also copy it to a clipboard for later use, and then trying to display large, doesn't work. (results in 'S').
I am vastly curious as to what "Trimming" is doing such that it changes this result - is it the nullchar/string strangeness that's tripping it up? is it the ` characters in the returned string? and why doesn't it work in bash? (and, even with "Trim Errors" set to no, the macros all still result in the weird S^@t^@a^@ string if displayed in a window.)
The original source is something that appears to be 16-bits per character, yes. Ideally I'm trying to build a macro that will take both 8- & 16-bit base64-encoded strings, and return a nicely formatted readable/usable display & clipboard, for further examination. (I don't have other examples to hand, but they do exist, and I could probably generate some if needed.)
I'll give the tr a try; any suggestions for python?