// Assumes Modern Syntax // --- SET CURRENT APP VARIABLE NEEDED FOR DIALOGS & StandardAdditions.osax --- var app = Application.currentApplication() app.includeStandardAdditions = true // --- SET KME APP VARIABLE NEEDED TO GET/SET KM VARIABLES --- var kme = Application("Keyboard Maestro Engine"); //--- GET A KM VARIABLE --- // Returns empty string if it doesn't exist var someVarNameStr = kme.getvariable("KMVarNameToGet") || 'Default Value if NOT Found'; console.log("someVarNameStr: " + someVarNameStr) var someNewDataStr = "Text to be set to a KM var"; //--- SET A KM VARIABLE --- // Creates the Variable if it doesn't exist // Verify Variable in the KM App Preferences kme.setvariable("KMVarNameToSet", { to: someNewDataStr }); //--- GET TEXT ON CLIPBOARD --- var clipboardStr = app.theClipboard() console.log("clipboardStr: " + clipboardStr) var someDataStr = "Example text to put on clipboard" //--- COPY TO CLIPBOARD --- // Verify using KM Clipboard History Viewer app.setTheClipboardTo(someDataStr)