Skip to content

Instantly share code, notes, and snippets.

@chitacan
Last active December 11, 2015 08:09
Show Gist options
  • Save chitacan/4571390 to your computer and use it in GitHub Desktop.
Save chitacan/4571390 to your computer and use it in GitHub Desktop.
Simple apple script for select us keyboard layout. This can be integrated with sublime text.
tell application "System Events" to tell process "SystemUIServer"
tell (1st menu bar item of menu bar 1 whose description is "text input") to {click, click (menu 1's menu item "U.S.")}
end tell
end run

Select US Keyboard

what for

with Sublime Text 2's vintage mode, it's quite annoying when you're not use U.S. keyboard.

well, this small applescript will help you.

install

open AppleScript Editor and copy content of select-us-keyboard.applescript.

save it into <sublime packages directory>/Vintage.

add following code snippet to vintage.py.

# select u.s. keyboard layout
if (self.view.id() == self.view.window().active_view().id()):
  script_path = sublime.packages_path() + "/Vintage/select-us-keyboard.scpt"
  subprocess.Popen(["osascript",script_path], stdout=subprocess.PIPE).communicate()[0]

(don't forget to import subprocess module!!!)

now whenever you exit insert mode, sublime will select U.S. keyboard layout automatically :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment