-
-
Notifications
You must be signed in to change notification settings - Fork 838
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
Can you map shortcut keys to output strings? #2949
Comments
Yes. You need to spell out every single keystroke required, in a macro. Alternatively, you could use the shortcut to run a shell script which puts your desired string on the clipboard and then presses Command V to paste it in place. I do stuff like that in my macros, too. |
Thanks, 👍
But it can't output the text of a specific input method, such as automatically outputting "你好", and the json code will become very much.
Is there sample code? |
Without using the system clipboard? I don't know a way to avoid it, short of composing your entire string manually with a sequence of pressed keys. Using the clipboard is easier. But Unicode text like 你好 is tricky. However, this works:
This calls an AppleScript which puts the string on the clipboard, then presses paste. Here is that simple Hello.scpt:
I can't figure out how to make Unicode characters play nice, straight in the shell, which is why I dodged that with an AppleScript. Clunky but effective. |
Thank you very much for your reply. |
You’re welcome! |
You can use the following script to paste text directly while also preserving the current clipboard content { "description" : "l⌥p ⟶ こんにちは","manipulators":[
{ "type":"basic",
"from" :{"key_code":"p","modifiers":{"mandatory":["left_option"]}},
"to" :[{"shell_command":"osascript -e 'set temp to the clipboard \n set the clipboard to \"こんにちは\" \n tell application \"System Events\" \n keystroke \"v\" using command down \n delay 0.1 \n end tell \n set the clipboard to temp'"}]
} ]}, Though if you have many keybinds such as this one, it's best to use Goku with its much more ergonomic format that would look closer to this: {:profiles {:goku {:default true}}
:templates { ; define the script monstrosity in one place as a template
:sym "osascript -e 'set temp to the clipboard \n set the clipboard to \"%s\" \n tell application \"System Events\" \n keystroke \"v\" using command down \n delay 0.1 \n end tell \n set the clipboard to temp'"
}
:main [
{:des "l⌥p ⟶ こんにちは" :rules [
[:!Op [:sym "こんにちは"] ] ; simple print command
]}
]} |
The benefit of using yabai to focus spaces is that you can switch focus between already visible spaces, something the native "Switch to Desktop" functionality lacks. I noticed, however, that this isn't really an issue, since you can switch display focus with yabai without disabling SIP (must sadly be disabled for space focusing 😭), which moves the focus between already opened spaces when you're using multiple monitors. When only using your laptop, you only have one display, so focusing a visible space is redundant. The "Switch to Desktop" functionality is also much faster than the yabai counterpart (at least when using fish). One drawback from using "Switch to Desktop" is that it hijacks both specified the left and right modifier keys. With the EurKEY layout, this prevents us from typing e.g. the € sign with option-5. A workaround to this is using Karabiner and remapping right_option-5 to type the € sign for us! 🎉 Resources: pqrs-org/Karabiner-Elements#2949 (comment) pqrs-org/Karabiner-Elements#3157 (comment)
The benefit of using yabai to focus spaces is that you can switch focus between already visible spaces, something the native "Switch to Desktop" functionality lacks. I noticed, however, that this isn't really an issue, since you can switch display focus with yabai without disabling SIP (must sadly be disabled for space focusing 😭), which moves the focus between already opened spaces when you're using multiple monitors. When only using your laptop, you only have one display, so focusing a visible space is redundant. The "Switch to Desktop" functionality is also much faster than the yabai counterpart (at least when using fish). One drawback from using "Switch to Desktop" is that it hijacks both specified the left and right modifier keys. With the EurKEY layout, this prevents us from typing e.g. the € sign with option-5. A workaround to this is using Karabiner and remapping right_option-5 to type the € sign for us! 🎉 Resources: pqrs-org/Karabiner-Elements#2949 (comment) pqrs-org/Karabiner-Elements#3157 (comment)
For example, press the shortcut key in the text box, output "こんにちは".
The text was updated successfully, but these errors were encountered: