If there's a way, I missed it. I searched the forums but kept finding the same question I had and "there's no way" answers from before KM 9.
Is there a way--a native KM option or a macro someone has created--to change some of the KM default toggles and settings for various actions?
For instance, I'm doing a lot of Pause Until Found Image actions lately, and the default timeout is 99 Hours, which has been causing me some problems I had contacted @peternlewis about . I'd like to change the default to something more reasonable like 30 Seconds. Then, every Pause Until Found Image action I create will use that by default instead of 99 Hours.
I'd also like to be able to (maybe) toggle Restore Mouse Location to on in Click At Found Image actions, or to toggle Notify on Failure off as the default. I'm sure there are others I'd like to change, too.
It's unlikely Peter will ever add this functionality – because demand is not all that high, and it'd be complicated to do.
However – our intrepid and talented friend @DanThomas who was a software engineer in another life built KMFAM for this very purpose.
KMFAM is an outstanding piece of work – is quite comprehensive – is free – and is pretty turnkey.
Only a few folks have had much trouble installing it, and I believe Dan has been able to help all of them overcome their issues.
I would recommend this option, before you even consider trying to roll-your-own.
If you do decide to build your own mousetrap then you can use my macro above as an example.
To create your own custom actions you have to manually create the action with all your custom attributes and then copy it as XML.
My macro shows how to use that XML to create a new action – although its not completely straightforward, since it's part of a purpose-built macro.
If there's more interest I'll post a more basic example.
You can also create template macros in Keyboard Maestro with one template action each and use a Prompt With List action to insert them into the working macro.
I'm working on a proof-of-concept for this right now, but it's poor man's fare compared to KMFAM.
Your macro creates the new action at the start of the target macro using the AppleScript statement
set newAction to make new action with properties {name:"Macro Notes", xml:attributionActionXML} at beginning
(which is exactly where you need the attribution to be placed.)
What I'm after is to insert the new action just after the currently-selected action in whatever macro I'm editing. I've tried leaving off the
at beginning
but that just puts the new action at the end of the macro. I've searched high and low through the AppleScript documentation for how I might achieve this but with no success. Is there anything you could suggest?
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/01/08 06:46
# dMod: 2021/01/08 06:46
# Appl: Keyboard Maestro
# Task: Insert an Action After the Selected Action OR at end of Actions.
# Libs: None
# Osax: None
# Tags: @Applescript, @ccstone, @Script, @Keyboard_Maestro, @Insert, @Action, @After, @Selected
# Vers: 1.00b01
--------------------------------------------------------
(*
NOTES:
• This script will work as is – it contains a handler with a KM Action's XML.
• The script demonstrates how to add an action AFTER the selected action
OR at the END of the actions in the working macro – IF no action is
selected.
*)
--------------------------------------------------------
property actionName : "DEBUG -- Display Variable in Window and Cancel Macro"
--------------------------------------------------------
tell application "Keyboard Maestro"
--» Get first selected macro.
set firstSelectedMacro to first item of (get selected macros)
--» Get selected item.
set selectionList to selection
if length of selectionList > 0 then
set {selectedItem} to selectionList
if class of selectedItem = action then
tell firstSelectedMacro
set newAction to make new action with properties {name:actionName, xml:getSavedActionXML() of me} at after selectedItem
select newAction
end tell
else
tell firstSelectedMacro
set newAction to make new action with properties {name:actionName, xml:getSavedActionXML() of me} at after its last action
select newAction
end tell
end if
end if
end tell
--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on getSavedActionXML()
set newActionXML to text 2 thru -1 of "
<dict>
<key>ActionColor</key>
<string>Orange</string>
<key>ActionName</key>
<string>DEBUG -- Display Variable in Window and Cancel Macro</string>
<key>Actions</key>
<array>
<dict>
<key>Action</key>
<string>DisplayWindow</string>
<key>MacroActionType</key>
<string>InsertText</string>
<key>StyledText</key>
<data>
cnRmZAAAAAADAAAAAgAAAAcAAABUWFQucnRmAQAAAC50
AQAAKwAAAAEAAABsAQAAe1xydGYxXGFuc2lcYW5zaWNw
ZzEyNTJcY29jb2FydGYxNTA0XGNvY29hc3VicnRmODMw
CntcZm9udHRibFxmMFxmbmlsXGZjaGFyc2V0MCBIZWx2
ZXRpY2FOZXVlO30Ke1xjb2xvcnRibDtccmVkMjU1XGdy
ZWVuMjU1XGJsdWUyNTU7XHJlZDBcZ3JlZW4wXGJsdWUw
O30Ke1wqXGV4cGFuZGVkY29sb3J0Ymw7O1xjc2dyYXlc
YzA7fQpccGFyZFx0eDU2MFx0eDExMjBcdHgxNjgwXHR4
MjI0MFx0eDI4MDBcdHgzMzYwXHR4MzkyMFx0eDQ0ODBc
dHg1MDQwXHR4NTYwMFx0eDYxNjBcdHg2NzIwXHBhcmRp
cm5hdHVyYWxccGFydGlnaHRlbmZhY3RvcjAKClxmMFxm
czI2IFxjZjIgJVZhcmlhYmxlJWxvY2FsX0dvb2dsZVNl
YXJjaFN0cmluZ0Z1bGwlfQEAAAAjAAAAAQAAAAcAAABU
WFQucnRmEAAAAM7o1Vy2AQAAAAAAAAAAAAA=
</data>
<key>Text</key>
<string>%Variable%local_GoogleSearchStringFull%</string>
</dict>
<dict>
<key>Action</key>
<string>CancelThisMacro</string>
<key>MacroActionType</key>
<string>Cancel</string>
</dict>
</array>
<key>MacroActionType</key>
<string>Group</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
"
return newActionXML
end getSavedActionXML
--------------------------------------------------------
I can see why it's impossible to provide documentation covering the plethora of scriptable apps and, having once been a software developer, I know how easy it is to leave the documentation until the end when often there is not the will nor the budget to complete it!
So I'm really grateful that you have answered my query so expertly and so quickly. Thanks
Well, this is probably the only time I can say “l’m ahead of you”! I bought a full license for SD quite some time ago and it has been invaluable as I’ve been progressing with my AppleScript journey. However, given my patchy understanding of AppleScript I find it difficult sometimes to understand/interpret what it is that SD is actually showing me. I haven’t made much use of the LNS forum which I can see now is a mistake on my part.
Anyway - thanks for the pointers and generous help. It’s most appreciated.