XML Escape

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

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


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!


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


  • 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

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