Closed algrw-c closed 2 years ago
You can do it with a shell_command
[1] by triggering macros with AppleScript [2]. But, why not simply use "Hot Key" trigger? [3]
[1] https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/to/shell-command/ [2] https://wiki.keyboardmaestro.com/trigger/Script [3] https://wiki.keyboardmaestro.com/trigger/Hot_Key
Edit: Looking what others did will help you - https://github.com/pqrs-org/KE-complex_modifications/search?q=osascript.
Thanks for answering! I been using Hot Key trigger, but when i use it it activates the key too, I use this for Final Cut, and had space as one hot key, that run a macro, but when i press it the video resumes. I don't know much about programing so dont understand the 1 link or the second, sorry
Try this:
{
"title": "Trigger Keyboard Maestro macro",
"rules": [
{
"description": "Final Cut -> Space trigger someMacro",
"manipulators": [
{
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": ["^com.apple.finder$"]
}
],
"from": {
"key_code": "spacebar",
"modifiers": {
"optional": ["any"]
}
},
"to": [
{
"shell_command": "osascript -e 'tell application \"Keyboard Maestro Engine\"' -e 'do script \"Name or UID of your Macro\"' -e 'end tell'"
}
]
}
]
}
]
}
Change "Name or UID of your Macro" to your Macro's name/UID. To get UID, see https://wiki.keyboardmaestro.com/manual/Menus#Copy_UUID.
In bundle_identifiers
, change com.apple.finder
to your application's bundle identifier. You can also use "file path" of an app. You can find the bundle identifier and file path of an app in KarabinerElemnts menu > Launch EventViewer > Frontmost Application tab
(EventViewer is also available as an app - Karabiner-EventViewer.app
).
FYI, you can add more than one bundle identifier in bundle_identifiers
. Same goes for file_paths
. You may also use both of them. See https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/.
Save this in a file named someName.json
in ~/.config/karabiner/assets/complex_modifications/
folder.
Import it - KarabinerElements Preferences > Complex modifications > Add rule
.
Note: In shell_command
, there are two ways to execute AppleScript:
-e
command. If there is any double quotes("
) or backslash(\
) in it, you will have to escape it by prepending it with backslash. Just like what I have done..scpt
extension and you can use it like this - osascript path/to/yourScript.scpt
.This may help you - https://wiki.keyboardmaestro.com/manual/Scripting#AppleScript.
I don't know much about programing so dont understand the 1 link or the second, sorry
You don't need to know programming. Just read! It REALLY helps. That's how I came to know all these stuffs. And I am pretty sure many others are also like this. So, just read! 🙂
Edit:
I been using Hot Key trigger, but when i use it it activates the key too, I use this for Final Cut, and had space as one hot key, that run a macro, but when i press it the video resumes.
You should notify Keyboard Maestro devs about this.
Should this work? I am testing it whit alfred PD: I am trying it whit the integrated space bar Edit: This is working but while i am in Finder only, how do i so to use it in other apps?
Edit: This is working but while i am in Finder only, how do i so to use it in other apps?
Second point mentioned above:
--snip--
- In
bundle_identifiers
, changecom.apple.finder
to your application's bundle identifier. You can also use "file path" of an app. You can find the bundle identifier and file path of an app inKarabinerElemnts menu > Launch EventViewer > Frontmost Application tab
(EventViewer is also available as an app -Karabiner-EventViewer.app
).FYI, you can add more than one bundle identifier in
bundle_identifiers
. Same goes forfile_paths
. You may also use both of them. See https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/.--snip--
So, if you want this modification in, say Firefox, then add Firefox's bundle identifier or it's path.
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com.apple.finder$",
"^org.mozilla.firefox$"
]
}
]
You may also use file path or both of them. It's up to you. If you want it to work in all apps, then just remove conditions
.
A quick note on bundle_identifiers
and file_paths
: KarabinerElements consider these as regex and in regex,
^
) - match from the start of a string$
) - match to the end of a string.
) - match any characterIt is valid to write without these, but it may match other apps. See
**tl;dr - just add caret at the start and dollar at the end of a bundle identifier or file path.
This [1] may help you in case you want to use modifier keys.
Thank you very much, From where to where do i have to remove to take the conditions? And, is there a way to write complex modification in the same file? just to keep it more organised And last, is there anyway i can Thank you enought?
Thank you very much,
You're welcome! :-)
From where to where do i have to remove to take the conditions?
You can consider everything as key: value
pair. If you want to remove a key, remove the corresponding value; if it's inside brackets, remove up to and including the matching bracket. In the above code, conditions
's value is an array (square bracket), so remove everything up to and including the matching square bracket. You must also remove the trailing comma. So this is what you have to remove:
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": ["^com.apple.finder$"]
}
],
For those who are unfamiliar to JSON, it might be slightly difficult to find the matching bracket in plain text editor . So I highly recommend you to use a good editor (TextMate, Visual Studio Code, etc.). In these, you will get highlighting, you can collapse what's inside matching brackets(blocks) and/or you can jump to matching bracket. This really helps, especially when editing large file. Use these [1][2] to get an idea of what I am telling.
[1] https://jsonformatter.org/json-editor [2] https://jsonformatter.curiousconcept.com/ (only formatting and block folding)
And, is there a way to write complex modification in the same file? just to keep it more organised
Yes. All of your settings, modifications, including imported ones, are saved in ~/.config/karabiner/karabiner.json
. If you want to, you can directly edit it. But, when editing it, use a JSON validator before saving to prevent potential errors. In case you messed up, you can find backups at ~/.config/karabiner/automatic_backups/
.
And last, is there anyway i can Thank you enought?
Consider it Done ;)
One last question (Or I think) How do i convine them so they apear toghether instead of these:
(By toghether i mean in the same folder/class)
Add your modification rules in rules
array, which will be shown under the corresponding title
.
{
"title": "Trigger Keyboard Maestro macro",
"rules": [
{
"description": "rule 1",
"manipulators": [
{
...
}
]
},
{
"description": "rule 2",
"manipulators": [
{
...
}
]
}
]
}
^This will result in:
In short, whenever you see an array([ ]
- square brackets), you can consider it as a list and hence, can add more than one item. Example:
manipulators
- https://karabiner-elements.pqrs.org/docs/json/typical-complex-modifications-examples/#swap--and-conditions
-
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.apple\\.Terminal$",
"^com\\.googlecode\\.iterm2$",
]
},
{
"type": "variable_if",
"name": "terminal_mode",
"value": 1
}
]
from.modifiers.optional
/from.modifiers.mandatory
- ["left_shift", "command", "caps_lock"]to
in manipulators - https://github.com/pqrs-org/KE-complex_modifications/blob/004ced60b1b866145211f4720e3dc75c005293fc/public/json/vim_mode_plus.json#L3971-L3990etc...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello, is there any way to change from one key to a Personalised virtual key? I want to remap every key in a keyboard so i can program the keys whit Keyboard Maestro but don't want the key to be writen when i press it, just be detected by Keyboard Mestro