I'd like some help combining two simple shell scripts, and a couple of regex search & replaces, into one shell script. I'll try to make this as simple as I can.
The purpose of this is to take the "StyledText" from a Comment Action's XML, and convert it to HTML. My existing code works.
Here's the steps:
Save "StyledText" data, which is actually a base64-encoded string, to disk file "%Variable%Local_base64TempFilePath%".
Convert from base64 to text, using a shell script: base64 -d -i "$KMVAR_Local_base64TempFilePath"
-- into variable "Local_rtfText"
Run two regexes to remove cruft from start and end of Local_rtfText. Each search & replace replaces the matched text with nothing: ^([^{]*) }[^}]*$
Save to disk file "%Variable%Local_rtfTempFilePath%".
Convert to HTM, using a shell script: textutil -convert html "$KMVAR_Local_rtfTempFilePath" -stdout
I think the steps 2, 3, and 5 could be combined into one shell script. Preferably with some error checking, but that's probably not feasible, and in theory this shouldn't fail (ha ha).
Is there a reason why you aren't just "Filter: Decode Base64"ing the variable rather writing a temp file then shelling out? And you could then run textutil on your variable via stdin:
There actually is a reason, and it's because I want to do entire thing from JXA. With that said, I have to admit I didn't even think of that Filter option. Not that it'll help this specific situation, but I have another macro this will help in. So, thanks!