Has anyone figured out a way to get Hazel to trigger a hot key that would, in turn, trigger a macro in an app like KM? (Or open to any other suggestions on how folks have had success using the two apps together.)
Quote from Hazel user manual:
â Hazel rules can use AppleScript or JavaScript in either of two ways: to provide logic for a condition (the âPasses AppleScriptâ or âPasses JavaScriptâ attribute), or to perform an action when a rule matches (the âRun AppleScriptâ or âRun JavaScriptâ action). If you need to accomplish a task that Hazelâs conditions or actions alone donât cover, AppleScript or JavaScript may provide a solution.â
Since KM macros can be triggered using AppleScript/JavaScript/shell it would be easy to do as you ask. You could run other apps using the same techniques.
Sorry - Iâm away from my Mac so canât give more concrete examples.
See this post for the AppleScript syntax to run a KM macro by its UUID.
Thanks, @tiffle and @noisneil!
What would be an Apple Script to replicate pressing "âââ„C" on the keyboard (ignoring the quotation marks)? Would something like the following work?
tell application "System Events"
key code C using {control down, option down, command down}
end tell
key code 8
(not "C")
Thanks, @tiffle. So it would be the following...?
tell application "System Events"
key code 8 using {control down, option down, command down}
end tell
tell application "System Events"
key code 8 using {control down, option down, command down}
end tell
would be AppleScript triggering ââ„âC
Out of curiosity, what is it you're actually trying to do @alexcr - I mean the "big picture" not just key strokes?
Thanks again, @tiffle! I'm trying to get Hazel to trigger a macro via a hot key.
Firstly â why are you monkeying around with key codes when you can use keystroke to press the actual key?
tell application "System Events"
keystroke "c" using {control down, option down, command down}
end tell
Secondly â using keystrokes is is a bad idea when it's not the only option. You can run a specific macro from AppleScript by name or by UUID.
tell application "Keyboard Maestro Engine"
do script "Generic-Test 01"
end tell
tell application "Keyboard Maestro Engine"
do script "129475DB-3D45-0101-9090-8F2C9B67F66C"
end tell
Ah, good to know! I'm learning on the fly here.
Ah, this is very helpful. Where do you find a macro's UUID?
Select your macro and right-click or go to the Edit menu of the Keyboard Maestro Editor and look at the options in the Copy as menu.
Thatâs exactly why I asked the question⊠as I said in my first reply to you and as @ccstone has very clearly said, Hazel can use AppleScript/Javascript to directly trigger specific macros - no need to use keystrokes/codes at all!