Skip to content

Instantly share code, notes, and snippets.

@M3t0r
Created October 22, 2019 19:16
Show Gist options
  • Select an option

  • Save M3t0r/a50ea3453aa7740605bf8a08d4e70f2b to your computer and use it in GitHub Desktop.

Select an option

Save M3t0r/a50ea3453aa7740605bf8a08d4e70f2b to your computer and use it in GitHub Desktop.
Toggle macOS input method between two values
# adapted from https://stackoverflow.com/a/23741934/371128
tell application "System Events" to tell process "SystemUIServer"
tell (menu bar item 1 of menu bar 1 whose description is "text input")
# !! Sadly, we must *visibly* select (open) the text-input menu-bar extra in order to
# !! populate its menu with the available input sources.
click
tell menu 1
# I only have two input methods, so selecting the first that isn't active toggles them
click (first menu item whose value of attribute "AXMenuItemMarkChar" is not "✓")
end tell
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment