MACRO: Make Macro Alias

Gotcha. I knew this wouldn’t be for everyone. :slight_smile:

Good questions, though. Thanks.

Yeah, I’ve run into both of these problems too. Good solution. Embarrassingly simple.

I haven’t played with this yet, but I think there’s a much more important use for this. I have a lot of groups that are each active for a single application. I also have some groups containing macros that are active in a natural set of applications — something like all my editors, or except for my development tools, or occasionally something more specific such as the MS Office applications.

However, sometimes I have a macro that i want active in what is essentially a random set of applications. It would be nonsensical to create separate groups for each of these random combinations of applications. Much better to store the original macro outside of the application groups and put an alias in each application’s group.

1 Like

Very cool macro. Perhaps I’ll have to implement Command-Option-dragging to make alias macros…


Just so you know, I’ll never be unhappy if you natively implement any of my ideas. It’s not like I’m a cottage industry and you’ll take away my livelihood. :stuck_out_tongue:

1 Like

Very nice and useful. Thanks.

(FWIW – the first few times I used the macro, KM “bonked” and nothing happened. It later began working. Most likely clueless user error, but maybe not.)

My guess is that one of the pauses isn't long enough in the macro. When something gets copied to the clipboard, there's no way to tell when it actually finishes getting copied.

So if it happens again, my guess would be that the last Pause action isn't long enough. It's right before the "Paste" action, right near the bottom before the "Cleanup Variables" group:

It's at .4 seconds, so you could try increasing it to .6, or higher, and see if that helps.

If you end up doing this and it solves your problem, I'd appreciate it if you posted here to let me know.


Dan, here’s a JXA snippet that waits for the clipboard to change. This was inspired by a comment from Peter that the KM Copy action does this. I just wrote this yesterday, so It has had only very limited testing, but seems to work well so far.

EDIT: 2016-06-18 15:56 CT (Sat)

var timeLimitSec = 5
var clipStr = ""

//--- Set the Clipboard so we can test for no selection ---

//### Do something to put content on Clipboard, like an App COPY ### 
//--- This is just an excerpt from the complete coded required ---
seApp.keystroke('c', { using: 'command down' }) // Press ⌘C
//. . .


  var startTime = new Date().getTime()  // number of milliseconds since 1970/01/01
  var timeLimitMs = timeLimitSec * 1000.0
  while ((new Date().getTime() - startTime) < timeLimitMs) {
    delay(0.2)  // adjust the delay as needed
    //--- Get the contents of the Clipboard ---
   clipStr = app.theClipboard()
    if (clipStr !== "[NONE]") break;
  } // END WHILE waiting for copy to complete

For complete code, see:
Copy & Get Selection to Clipboard JXA.js

At 0.7 I get no bonks – although that seems like splitting hairs. To be scientific, I’d have to try to different times while aliasing every macro in my library. Probably not going to have time for that :sweat_smile: this decade.

Thanks. I going to change the script so it checks to make sure the data is on the clipboard. Thanks for verifying that’s the issue!

Perfect. You are clairvoyant!!

Oh, wait - that’s in JXA. I already know how to do that. Let’s continue this in the other topic.

I can’t use cmd+c for the copy. I need to set a specific clipboard format. Thanks for trying, though!

Got an answer, I think. I’ll post it shortly. Just didn’t want you to waste any more time.

korm - Can you try this version and let me know if it works for you? Thanks.

[attachment removed]

Sorry for the delay in testing.


No problem. Thanks for trying it.

What version of OS/X are you on?


Dang. I have no idea.

Well, it’s not that important. Keep using v1.0 with the pause set to whatever you need.

I’ll think on it a while. As I said, it’s not that important, but this kind of stuff drives me crazy (as you can tell by how quickly I responded). It’s like an itch I can’t ignore for long. :slight_smile:

Thanks for your help! I truly appreciate it. Most people usually just give up when there’s an issue, and the developer never knows about it. (Been guilty of doing that many times myself, as a user. :open_mouth: )

FWIW, when ScriptDebugger attempts to compile the script in “put the new macro on the clipboard, as an actual macro…” the compile fails at this line

set {_object, _error} to current application's NSPropertyListSerialization's propertyListWithData:_data options:0 format:(missing value) |error|:(reference)

with this error

Expected end of line, etc. but found “:”.

There may be other compilation errors in other actions, btw – didn’t check every possible compilation

It’s always a good idea when writing macros to run included code through Script Editor or ScriptDebugger to track errors, since KM does not throw useful messages about these things