Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Created May 21, 2018 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongyuwei/e82cbd0f5f8ed65842bd421a2a6ac023 to your computer and use it in GitHub Desktop.
Save dongyuwei/e82cbd0f5f8ed65842bd421a2a6ac023 to your computer and use it in GitHub Desktop.
const exec = require("child_process").execSync;
const devicePreferences = exec(
`/usr/libexec/PlistBuddy -c "Print :DevicePreferences" ~/Library/Preferences/com.apple.iphonesimulator.plist`
).toString();
const regexp = /\s+([A-Za-z0-9-]+)\s=\sDict\s\{/g;
let matched = [];
while ((matched = regexp.exec(devicePreferences)) !== null) {
const simulatorUuid = matched[1];
try {
exec(
`/usr/libexec/PlistBuddy -c "Set :DevicePreferences:${simulatorUuid}:ConnectHardwareKeyboard false" ~/Library/Preferences/com.apple.iphonesimulator.plist`
);
} catch (error) {
exec(
`/usr/libexec/PlistBuddy -c "Add :DevicePreferences:${simulatorUuid}:ConnectHardwareKeyboard bool false" ~/Library/Preferences/com.apple.iphonesimulator.plist`
);
}
}
@dongyuwei
Copy link
Author

tell application "Simulator"
    activate
end tell

tell application "System Events"
    set hwKB to value of attribute "AXMenuItemMarkChar" of menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "Hardware" of menu bar 1 of application process "Simulator"
    if ((hwKB as string) is equal to "missing value") then
      do shell script "echo 'hardware keyboard is off'"
    else
      click menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "Hardware" of menu bar 1 of application process "Simulator"
    end if
end tell

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