// Name: Keyboard Maestro // Description: Run or edit a Keyboard Maestro macro // Author: Pavel 'Strajk' Dolecek // Twitter: @straaajk // Cache: true import "@johnlindquist/kit" import plist from 'plist' import dedent from "dedent" export type TMacro = Partial<{ name: string uid: string active: boolean created: number used: number enabled: boolean lastused: number modified: number saved: number sort: string triggers: Array<Partial<{ description: string, short: string, type: string }>> }> export type TMacroGroup = Partial<{ uid: string enabled: boolean name: string sort: string macros: TMacro[] }> let kmMacrosRaw = await applescript(dedent` tell application "Keyboard Maestro Engine" getmacros with asstring end tell `) let kmMacrosParsed = plist.parse(kmMacrosRaw) as TMacroGroup[] const choices = kmMacrosParsed.flatMap(group => group.macros.map(macro => ({ name: `${group.name} - ${macro.name}`, value: macro.uid }))) let chosen = await arg({ placeholder: "Choose a macro", choices: choices, actions: [ { shortcut: `${cmd}+e`, name: "Edit Macro", visible: true, flag: "edit" } ] }) if (flag.edit) { // Note that flag is a global await applescript(dedent` tell application "Keyboard Maestro" editMacro "${chosen}" activate end tell `) } else { await applescript(dedent` tell application "Keyboard Maestro Engine" do script "${chosen}" end tell `) }