MacOS Sierra下如何修改或添加方括号「[ ]」的键盘快捷键?
Hey there! Customizing keyboard shortcuts for frequently used symbols like square brackets is such a smart move to boost your programming workflow—totally feel your pain with the clunky Alt+Shift+( combo on macOS Sierra. Here are two solid ways to set up your preferred Cmd+( shortcut:
方法1:用Automator创建自定义插入服务(无额外软件)
This uses built-in macOS tools, so no need to install anything:
- Open Automator (found in your Applications folder) and select "Service" when prompted to create a new document.
- At the top of the workflow window, set "Service receives" to no input and "in" to any application.
- In the left-hand action library, search for "Run AppleScript" and drag it into the right-hand workflow area.
- Replace the default AppleScript code with this snippet:
tell application "System Events" keystroke "[" using command down end tell
- Press
Cmd + Sto save the service—name it something clear like "Insert Left Square Bracket". - Head to System Preferences > Keyboard > Shortcuts > Services, find your new service, click the empty space next to it, and press
Cmd + (to assign the shortcut. - Pro tip: If the shortcut is already in use, macOS will alert you—you can either reassign the conflicting shortcut or pick a slightly different combo.
方法2:用Karabiner-Elements(更灵活的键盘自定义)
If you want more control (like app-specific shortcuts or multiple key remaps), Karabiner-Elements is the go-to tool for macOS keyboard customization (just make sure you grab a version compatible with Sierra):
- Install Karabiner-Elements and open the app.
- Navigate to the Complex Modifications tab, then click "Add rule".
- You can either search for a pre-made square bracket remap rule or create your own:
- Click "Create a new rule" and name it something like "Cmd + ( → Left Square Bracket".
- Under "From key", select
(and check the "Command" modifier box. - Under "To key", select
[(no modifiers needed). - Save the rule and toggle it on.
- Now
Cmd + (will directly input[—you can even set this rule to only apply to your favorite IDEs if you want.
Quick Notes
- For the Automator method to work, you may need to grant Automator access in System Preferences > Security & Privacy > Privacy > Accessibility.
- Always test your new shortcut in your coding app first to make sure it doesn't conflict with existing IDE shortcuts (like indentation or code folding).
内容的提问来源于stack exchange,提问作者Beno
相关产品推荐
相关产品推荐

