I am using macOS Catalina v10.15.7. I am using Control+Space
to select text in emacs
. In order to achieve I am deselecting Select the previous input source
and Select the next source Input menu
.
=> Settings => Keyboard => Shortcuts => Input Sources
[ ] Select the previous input source # deselected
[ ] Select next source in input menu # deseleced
So when I press Contol+Space
not it does not open open Input Source
window.
In some cases I believe if macOS crashed or if I force macOS to shutdown by pressing the power button, after opening macOS and when I press control+space
it is bound to Input Source
even if (Select the previous input source Select next source in input menu) are deselected under the setting.
Is it possible to change input sources's setting using a script in startup as
-
First select Select the previous input source and Select next source in input menu
-
Then deselect Select the previous input source and *Select next source in input menu
=> Settings => Keyboard => Shortcuts => Input Sources
[X] Select the previous input source # selected
[X] Select next source in input menu # selected
then
[ ] Select the previous input source # deselected
[ ] Select next source in input menu # deseleced
- I am using
Control+Space
constantly mark/unmark text inemacs
, which is the default keybinding.
C-SPC Set the mark at point, and activate it (set-mark-command).
Best Answer
The example AppleScript code, show further below, was tested under macOS Catalina with Language & Region settings in System Preferences set to English/English (US) — Primary and Input Sources in System Preferences > Keyboard set to U.S.. It was tested in Script Editor as a script and tested saved as an application and added to Login Items in System Preferences > Users & Groups for the target User.
For testing purpose as an application, I saved it as Uncheck Input Sources add added it to System Preferences > Security & Privacy > Privacy > Accessibility. After which the first time I ran it manually, to see that it worked, I was asked...
Don't Allow OK
To which I clicked: OK
I then tested it, rebooting the system a couple times and it appeared to work without issue.
NOTE: This uses UI Scripting and System Events to toggle the target checkboxes in System Preferences > Keyboard > Shortcuts > Input Sources and it is done so without showing the UI of System Preferences, however, it still has to open it and do its thing. Keep this in mind when logging in, and allow the process to complete before doing anything else. It should only take a few seconds. (Such is the nature of UI Scripting.)
Example AppleScript code:
Because of the comments and coding style the script is very long. It ends with
end clickCheckbox
, so make sure you highlight all of it when copying and pasting to Script Editor for testing before saving it as an application for production purposes.Notes:
As coded, the
repeat
loops are set to timeout after two seconds if the primary condition is not met first. If the timeout is reached, the script is stopped without any error message. This can be modified as needed/wanted/required.If you do not want the icon of saved AppleScript application shown in the Dock, then in Terminal use the following command syntax while changing
/path/to/$name.app
in the example command'/path/to/$name.app/Contents/Info.plist'
to the pathname of the saved AppleScript application:For my testing purposes I used:
If you modify the saved AppleScript application bundle after it has already been authorized to run, then you will need to reauthorize it before the system reboots again. Go to System Preferences > Security & Privacy > Privacy > Accessibility and uncheck the checkbox for the target application and then recheck it. Then run the saved AppleScript application manually to answer OK to the dialog box that appear. The saved Safari application is now read for production use and no icon for it should appear in the Dock.
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g.
delay 0.5
, with the value of the delay set appropriately.