Hey Folks,
@gglick has come up with a pretty good solution.
One thing to note is that you DON’T have to run a do script AppleScript command using a UUID.
You can simply use the name. (Of course you have to be certain that name is unique.)
It’s as simple as this:
tell application "Keyboard Maestro Engine"
do script "Dropbox path"
end tell
So — if you can be certain your macro names are unique you don’t have to go through the fuss of managing macro UUIDs — saving time and effort.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/10 23:10
# dMod: 2017/11/12 22:36
# Appl: Keyboard Maestro
# Task: Run one or more macros from a given macro group from a pick-list (no UUIDs).
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Keyboard_Maestro, @Run, @Macros, @MacroGroup, @Pick-list
------------------------------------------------------------------------------
property macroGroupName : "Global Macro Group"
------------------------------------------------------------------------------
tell application "Keyboard Maestro"
tell macro group macroGroupName
set macroNameList to name of macros
end tell
end tell
tell application (path to frontmost application as text)
set theChosen to (choose from list macroNameList with title "Macro List" with prompt "Select a macro to run:" default items {item 1 of macroNameList} ¬
with multiple selections allowed)
end tell
if theChosen = false then return
tell application "Keyboard Maestro Engine"
repeat with theMacroName in theChosen
do script theMacroName
end repeat
end tell
------------------------------------------------------------------------------
On the other hand — if you NEED to make use of UUIDs then here’s an alternative method that uses matched lists of macro-name and macro-id.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/10 23:10
# dMod: 2017/11/10 23:26
# Appl: Keyboard Maestro
# Task: Run one or more macros from a given macro group from a pick-list.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Keyboard_Maestro, @Run, @Macros, @MacroGroup, @Pick-list
------------------------------------------------------------------------------
use AppleScript version "2.4" # requires Yosemite or higher
use framework "Foundation"
use scripting additions
------------------------------------------------------------------------------
property macroGroupName : "Global Macro Group"
------------------------------------------------------------------------------
tell application "Keyboard Maestro"
tell macro group macroGroupName
set {macroNameList, macroIdList} to {name of macros, id of macros}
end tell
end tell
tell application (path to frontmost application as text)
set theChosen to (choose from list macroNameList with title "Macro List" with prompt "Select a macro to run:" default items {item 1 of macroNameList} ¬
with multiple selections allowed)
end tell
if theChosen = false then return
tell application "Keyboard Maestro Engine"
repeat with i in theChosen
do script (item (my indexOf:(contents of i) inList:macroNameList) of macroIdList)
end repeat
end tell
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
# Find offset of an item in a list.
------------------------------------------------------------------------------
on indexOf:aValue inList:theList
local currentApp, theArray, theIndex
set currentApp to current application
set theIndex to (currentApp's NSArray's arrayWithArray:theList)'s indexOfObject:aValue
if theIndex = currentApp's NSNotFound then
return "null"
else
return (theIndex + 1) # +1 because ASObjC counts starting from 0
end if
end indexOf:inList:
------------------------------------------------------------------------------
This method is handy, because you don’t need to concatenate anything.
It will present you with a choose-from list of macro-names and then run the associated UUID(s) of the macros you pick.
-Chris
[Edited 2017/11/12 22:37 CST to remove a little cruft from the first AppleScript.]