[Feature Request] Go to Macro in Execute a Macro

In addition to which, I might use the same submacro from several different groups. (That complicates packaging if I want to share the group with others, but makes things easier for me. I have started to have a couple of Utility groups that contain just submacros. And I should put the name of the groups that use the submacro in its comment. That would improve things in that there are only a small number of groups where I would find the macro. (This doesn’t work if I use a top-level macro also as a submacro.)

I just an interesting case where two macro groups I have been trying to distribute for a couple of weeks share one submacro. I ended up just doing a copy and paste, and every time I edited the macro I had to repeat the copy and paste. In the end this isn’t going to work for me because I don’t want the submacro appearing in the group’s palette, but sometimes it might be a reasonable way to go.

I'm keeping it simple: I put ALL of my sub-macros in a Group named "Sub-Macros".

Makes it easy to find and maintain.

That's not the point - it's when there's an Execute Macro, it makes it easier to find the referenced macro. That doesn't show at the top, does it?

Of course if they're all in one group, that solves that issue. But even if I were to put all sub-macros in one group, I'd prefix the ones that are app-specific so I could find, say, all Mail-related sub-macros.

Yep, I've been doing that for a while with all of my macros, not just sub-macros.
I use a very brief code, in brackets, like "[OL]" for Outlook focused macros.

So then, you mostly use groups only for Palettes and application-available macros?

Yep. See:

You know, I saw that, but I didn’t put it all together. Sometimes I miss the forest for the trees.

That’s what I have been doing, though I think I split it into two groups: UI manipulations and macros that do more programming-like tasks (macros, AppleScripts, soon I hope ASOjbc, etc.). Not a clear distinction, but good enough. Until I have tens of macros in one of the groups, then I’ll split.

Hey Folks,

Courtesy of Shane Stanley.

I'll get back again as soon as I find out how to put the KM-Action and KM-Macro data-types back on the Clipboard.

-Chris

---------------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2016/06/03 22:05
# dMod: 2016/06/03 22:33
# Appl: Keyboard Maestro
# Task: Extract Keyboard Maestro action or macro plist from the clipboard.
# Aojc: True
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Extract, @Keyboard_Maestro, @Plist
---------------------------------------------------------------------------------
use framework "Foundation"
use scripting additions
---------------------------------------------------------------------------------

set kmPlistStr to missing value
set systemPasteBoard to current application's NSPasteboard's generalPasteboard()

if (systemPasteBoard's canReadItemWithDataConformingToTypes:{"com.stairways.keyboardmaestro.actionarray"}) as boolean then
  # Copied Action or Actions
  set kmPlistStr to systemPasteBoard's stringForType:"com.stairways.keyboardmaestro.actionarray"
else if (systemPasteBoard's canReadItemWithDataConformingToTypes:{"com.stairways.keyboardmaestro.macrosarray"}) as boolean then
  # Copied Macro or Macros
  set kmPlistStr to systemPasteBoard's stringForType:"com.stairways.keyboardmaestro.macrosarray"
end if

if kmPlistStr ≠ missing value then
  return kmPlistStr as text
else
  beep
end if

---------------------------------------------------------------------------------

Hey Folks,

Again courtesy of Shane Stanley.

This script will put a Keyboard Maestro Action on the Clipboard ready for pasting into a macro.

The same script with the alternate data-type can be used to put a Keyboard Maestro Macro on the Clipboard ready for pasting.

-Chris

---------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/06/03 22:45
# dMod: 2016/06/03 22:56
# Appl: Keyboard Maestro
# Task: Put Action or Macro Plist data on the clipboard with appropriate data-type.
# Aojc: True
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Plist, @ASObjC
---------------------------------------------------------------------------------
use framework "Foundation"
use scripting additions
---------------------------------------------------------------------------------

# Action data-type 
set kmPasteboardDataType to "com.stairways.keyboardmaestro.actionarray"

# Macro data-type 
# set kmPasteboardDataType to "com.stairways.keyboardmaestro.macrosarray"


set kmPlistData to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<array>
  <dict>
    <key>MacroActionType</key>
    <string>Notification</string>
    <key>SoundName</key>
    <string>Tink</string>
    <key>Subtitle</key>
    <string>EUREKA!  IT WORKS!</string>
    <key>Text</key>
    <string></string>
    <key>Title</key>
    <string>%ExecutingMacro%</string>
  </dict>
</array>
</plist>
"

set systemPasteBoard to current application's NSPasteboard's generalPasteboard()
systemPasteBoard's clearContents()
systemPasteBoard's setString:kmPlistData forType:kmPasteboardDataType

---------------------------------------------------------------------------------

Hey Chris, maybe I missed something, but I thought the objective was to read the plist/XML to get the sub-macro name, and then open that macro for editing.

Hey Folks,

Okay, let’s build upon the “Extract Keyboard Maestro action or macro plist from the clipboard” script.

Open a macro that has an Execute a Macro action in it.

Select that action.

Copy it to the Clipboard.

Run the script.

Find yourself editing the macro called by the selected Execute a Macro action.

-Chris

---------------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2016/06/03 22:05
# dMod: 2016/06/04 01:16
# Appl: Keyboard Maestro
# Task: GO-TO macro of selected “Execute a Macro” action in the Keyboard Maestro Editor.
# Aojc: True
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Extract, @Keyboard_Maestro, @Plist
---------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
---------------------------------------------------------------------------------

set kmPlistStr to missing value
set actionUUID to missing value
set systemPasteBoard to current application's NSPasteboard's generalPasteboard()

if (systemPasteBoard's canReadItemWithDataConformingToTypes:{"com.stairways.keyboardmaestro.actionarray"}) as boolean then
  # Copied Action or Actions
  set kmPlistStr to systemPasteBoard's stringForType:"com.stairways.keyboardmaestro.actionarray"
end if

if kmPlistStr ≠ missing value then
  set kmPlistStr to kmPlistStr as text
  
  tell application "System Events"
    set actionPlistRecord to value of (make property list item with properties {text:kmPlistStr})
    set actionUUID to MacroUID of item 1 of actionPlistRecord
  end tell
  
  if actionUUID ≠ missing value then
    tell application "Keyboard Maestro"
      editMacro actionUUID
    end tell
  end if
  
else
  beep
end if

---------------------------------------------------------------------------------
1 Like

@peternlewis - If we start deciphering KM’s Clipboard format like this, what kind of headache will this cause either you or us in the future? Do you see yourself needing to change the clipboard format itself? I realize the values in the plists will change, but what about the format itself?

I'm staring at my keyboard, trying to figure out how to describe the feelings I'm having right now, watching this work on my machine.

If I said I wanted to kiss you, would you take it the wrong way? How about a high-five then. Simply. Awesome.

Also, the timeliness of the code for deciphering the clipboard is downright spooky, considering what I'm working on right now. Again, awesome.

Did I say "Thanks"? Thanks.

2 Likes

Alright guys, here’s what I want next:

I want a palette, or something palette-like, where I can put the names of the macros I’m currently working on, so I click or double-click a macro and jump right to it in the editor.

Pie-in-the-sky, I’d be able to drag-re-order the list, drag macros to it, remove macros from it, etc.

I have to admit that although just about anything is possible, I don’t expect to get this. But “you have not because you ask not”, so, I’m putting this out there.

I make no promises on the internal format of the macro files, not on the format or arrangement of the Keyboard Maestro preferences folder.

Enjoy whatever you like for as long as it lasts, but if it makes sense to change the format at some point in the future, it'll change and any macros or workflows that depend on it will have to be reworked - I can't afford to have progress of Keyboard Maestro limited by this sort of thing. I could just say "its all private, don't touch", but you may as well get as much value out of it as you can in the mean time, and that time might be decades for all I know.

Good response.

I was also concerned that we might be distressing you with the thought of us tinkering like this. Glad to know you’re cool with it.

Looks like I didn't post this here or if I did I missed it.

@JMichaelTX - Can you mark this topic as "Solved"?

Since @MitchellModel posted the original topic/question, protocol suggests that he should select the post which is "best answer" or "Solved".

1 Like

Protocol? We have Protocol? … just kidding