Plug-in "TokenString" field

OK, I just tested one of my old plugins, XML Escape. When I use %Variable% syntax, it works regardless of whether it's a local or global variable.

image

Here's my plist:

<?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>Author</key>
	<string>@DanThomas</string>
	<key>Help</key>
	<string>Escape a string for use in XML</string>
	<key>Icon</key>
	<string>Icon.png</string>
	<key>Name</key>
	<string>XML Escape</string>
	<key>Parameters</key>
	<array>
		<dict>
			<key>Label</key>
			<string>Escape Text</string>
			<key>Type</key>
			<string>TokenString</string>
		</dict>
	</array>
	<key>Results</key>
	<string>Variable|Clipboard|Window|Briefly|Typing|Pasting</string>
	<key>Script</key>
	<string>Action.scpt</string>
	<key>Title</key>
	<string>XML Escape '%Param%Escape Text%'</string>
</dict>
</plist>

Here's my script:

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;';
        }
    });
}

var kme = Application("Keyboard Maestro Engine");
var text = ObjC.unwrap($.NSProcessInfo.processInfo.environment.objectForKey("KMPARAM_Escape_Text"))
var xml = escapeXml(text);
xml;

I hope this helps.

2 Likes