Hey guys,
I’ve found a few bash commands that do this, but none of them seem to handle encode of multiple lines.
I’m hoping there is a ASObjC solution for this. Can anyone point me in the right direction?
I could also use help in extracting the encoded string from a XML string I get from an Keyboard Maestro Action object. It looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Action</key>
<string>DisplayWindow</string>
<key>MacroActionType</key>
<string>InsertText</string>
<key>StyledText</key>
<data>
cnRmZAAAAAADAAAAAgAAAAcAAABUWFQucnRmAQAAAC5WAQAAKwAAAAEAAABOAQAAe1xy
dGYxXGFuc2lcYW5zaWNwZzEyNTJcY29jb2FydGYxNDA0XGNvY29hc3VicnRmNDcwCntc
Zm9udHRibFxmMFxmbmlsXGZjaGFyc2V0MCBIZWx2ZXRpY2FOZXVlO30Ke1xjb2xvcnRi
bDtccmVkMjU1XGdyZWVuMjU1XGJsdWUyNTU7fQpccGFyZFx0eDU2MFx0eDExMjBcdHgx
NjgwXHR4MjI0MFx0eDI4MDBcdHgzMzYwXHR4MzkyMFx0eDQ0ODBcdHg1MDQwXHR4NTYw
MFx0eDYxNjBcdHg2NzIwXHBhcmRpcm5hdHVyYWxccGFydGlnaHRlbmZhY3RvcjAKClxm
MFxmczI2IFxjZjAgJVZhcmlhYmxlJVRFU1RfX0VsYXBzZWRUaW1lJVwKVEVTVF9fVmFy
MjoJJVZhcmlhYmxlJVRFU1RfX1ZhcjIlfQEAAAAjAAAAAQAAAAcAAABUWFQucnRmEAAA
AJ4Ez1m2AQAAAAAAAAAAAAA=
</data>
<key>Text</key>
<string>%Variable%TEST__ElapsedTime%
TEST__Var2: %Variable%TEST__Var2%</string>
</dict>
</plist>
The text I need to decode is in the
<key>StyledText</key>
<data>
-- rich text base64 encoded
</data>
So I need to:
- extract the rich text base64 encoded from the XML string.
- base64 Decode (results in multiple lines)
- Make some changes
- base64 encode multiple lines – haven’t been able to do this
- Update the xml source.
The only part I have not been able to figure out is #4.
I’ve been using RegEx for find, and then replace, but I’m thinking there is probably a better ASObjC dictionary method that I could/should use.
Here is the bash script, but it fails with multiple lines:
set encodedStr to "cnRmZAAAAAADAAAAAgAAAAcAAABUWFQucnRmAQAAAC5LAQAAKwAAAAEAAABDAQAAe1xy
dGYxXGFuc2lcYW5zaWNwZzEyNTJcY29jb2FydGYxNDA0XGNvY29hc3VicnRmNDcwCntc
Zm9udHRibFxmMFxmbmlsXGZjaGFyc2V0MCBIZWx2ZXRpY2FOZXVlO30Ke1xjb2xvcnRi
bDtccmVkMjU1XGdyZWVuMjU1XGJsdWUyNTU7XHJlZDBcZ3JlZW4wXGJsdWUwO30KXHBh
cmRcdHg1NjBcdHgxMTIwXHR4MTY4MFx0eDIyNDBcdHgyODAwXHR4MzM2MFx0eDM5MjBc
dHg0NDgwXHR4NTA0MFx0eDU2MDBcdHg2MTYwXHR4NjcyMFxwYXJkaXJuYXR1cmFsXHBh
cnRpZ2h0ZW5mYWN0b3IwCgpcZjBcZnMyNiBcY2YyIFRFU1RfX1ZhcjM6CSVWYXJpYWJs
ZSVURVNUX19WYXIzJX0BAAAAIwAAAAEAAAAHAAAAVFhULnJ0ZhAAAABoCs9ZtgEAAAAA
AAAAAAAA"
--- base64 DECODE THE STRING --
set cmdStr to "echo '" & encodedStr & "' | openssl base64 -d"
set decodedStr to do shell script cmdStr
### In my production script will make changes to decodedStr here ###
--- NOW, base64 ENCODE after my changes ---
-- for testing, just encoding what I just decoded
set cmdStr to "echo -n '" & decodedStr & "' | openssl base64"
set encoded2Str to do shell script cmdStr
-->ERROR:
(*
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
*)
TIA for all help and suggestions.