Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass arguments to a keyboard maestro macro? #29

Open
davidawad opened this issue Feb 10, 2022 · 6 comments
Open

How to pass arguments to a keyboard maestro macro? #29

davidawad opened this issue Feb 10, 2022 · 6 comments

Comments

@davidawad
Copy link

Hey Ian,

I don't know if this is documented somewhere, but is it possible to use alfred maestro to pass arguments into a keyboard maestro macro.

Meaning I could type 'km drive taxes' and then run a keyboard maestro macro that supplies 'taxes' or '$@' into my macro as a query param to google.com or use those variables however I want.

I would love to see an example of that if that’s possible.

Thanks so much.

@iansinnott
Copy link
Owner

Hey @davidawad, interesting use case. Unfortunately, it's not currently possible. The macros will be executed by AppleScript using the UID of the macro in question. In other words, no additional arguments are passed:

-- The passed query is the UID of the macro
tell application "Keyboard Maestro Engine"
  do script "{query}"
end tell

@davidawad
Copy link
Author

hey @iansinnott sorry for the late reply.
How about a workaround, what if we use the clipboard to pass the message between applications?

Then all you need to do is save the argument from alfred to clipboard, and KM just reads it from there.

@davidawad
Copy link
Author

davidawad commented Mar 5, 2022

Ok I've done some digging into this,

I'm not a go programmer but I'm pretty sure you can add an if statement around here:
https://github.com/iansinnott/alfred-maestro/blob/master/main.go#L56

you can take the second argument, meaning

km <WORKFLOW> <ARG>

and just add an if statement on the filter, if it sees a $2 (or better yet $@ it can copy that to the clipboard, that way the corresponding macro can read from the clipboard and we can get our message-passing working. in my opinion the filtering should filter ONLY on arg 1, so we can enable passing args, but that also means you can only trigger workflows with single word names. This may be desirable behavior to have shorter names given the point of alfred but it's still a restriction.

For now, my workaround was to type the second arg and copy with pbcopy. This requires running it twice, but gives me something close to what I wanted. Maybe a package like this (https://github.com/golang-design/clipboard) could write the second arg to the clipboard?

image

@davidawad
Copy link
Author

what do you think @iansinnott ?

@iansinnott
Copy link
Owner

you can only trigger workflows with single word names

This is a significant tradeoff and would break workflows for existing users, so I'm loth to introduce such a breaking change. One of the unstated goals when creating alfred maestro was to be able to call macros by name, allowing potentially long but semantically meaningful macro names.

@davidawad
Copy link
Author

hrmm, maybe there's an option or flag we can set in the alfred script if users want to use the clipboard for arg passing?

I wouldn't want to fork the plugin for this as you've done great work already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants