XML Escape

A custom action that "escapes" a text string to make it usable in XML.

XML Escape.v1.0.zip (7.2 KB)

Results:

Here's the JXA I used for the encoding:

function escapeXml(unsafe) {
    return unsafe.replace(/[<>&'"]/g, function (c) {
        switch (c) {
            case '<': return '&lt;';
            case '>': return '&gt;';
            case '&': return '&amp;';
            case '\'': return '&apos;';
            case '"': return '&quot;';
        }
    });
}

I got this from StackOverflow, and it's quite possible it doesn't cover everything. If that's the case, please let me know so I can update it. Thanks!

REQUIREMENTS

  • Yosemite
    • The underlying scripts are written in Javascript for Applications

INSTALLATION

  • Drag the .zip file you require onto the Keyboard Maestro icon in the OS X Dock.
  • (if updating a previous version of the action, first manually remove the previous copy from the custom actions folder)
    • ~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions
3 Likes

I keep writing that too …

--> 'JavaScript for Automation'

Yeah, I know - I stole that whole section from you! :sweat_smile:

1 Like

Good to see more JavaScript resources building up …

1 Like

Hey Dan (@DanThomas),

This is a nice PlugIn which I use quite often in my Macros for a while now - especially with your Example Macro Dynamic Prompt for User Input.
It makes it so much better Writing Macros with the Prompt for User Input Action for me.

Thank you for providing this ....

I am writing this because I use Version 1.1 of this PlugIn Action which I downloaded a long time ago (don't know when....) and I really don't know from where I downloaded it...

It would be nice if you could add the Version 1.1 for others in the OP.

Another nice thing would be If you could fix a problem that occours when using the Action and you are on an older OS that allows the use of Osaxen.

One of these Osaxen is the XML Tools.osax by LateNight Software.Ltd

If I have it Installed on my MacBook Pro from 2010 - I get this Message:

osascript: OpenScripting.framework - scripting addition "/Users/kurty_309/Library/ScriptingAdditions/XML Tools.osax" cannot be used with the current OS because it has no OSAXHandlers entry in its Info.plist.

If it is not installed every thing is okay and I don't get any Error Message.

Just to be clear - The Action Works everything is fine but I have to move the Osax out of its System Folder whenever I use this Action and later put it back ....

It is a pain because it requires also recompiling of any AppleScript I have that uses this Osax.

There has to be another way ... a way that I can keep the Osax installed.

Maybe Chris (@ccstone) can help here, too ?!

Greetings from Germany

Tobias

I honestly don't have a clue. Hopefully someone else can jump in here.