3 Replies Latest reply: Apr 16, 2006 1:51 AM by Michael Henley
Randy Farnsworth Level 1 Level 1 (35 points)
I use an external Windows keyboard on my PowerBook while at work, then use the internal keyboard at home. To keep from hitting the wrong keys all day, I open the sys prefs each morning and swap the Option and Command keys (Alt and Windows keys on the external keyboard), then swap them back each night at home. While this is easy enough to do, I'd like an AppleScript or Automator Task that can do this for me. Since I'm a novice when it comes to Automator and scripting, can anyone help me with this?

Thanks!

PowerBook G4 17 1.67GHz   Mac OS X (10.4.6)   Dell Windows External Keyboard (ugh!)
  • Randy Farnsworth Level 1 Level 1 (35 points)
    I solved this problem by finding and altering an applescript that will change the keyboard modifier keys. I wish I could still find the web page so I could post it, but here's the applescript I used to change to PC layout:

    tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.keyboard"
    end tell

    tell application "System Events"
    tell process "System Preferences"
    click radio button "Keyboard" of tab group 1 of window "Keyboard & Mouse"
    click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"

    click pop up button 3 of sheet 1 of window "Keyboard & Mouse"
    click menu item 4 of menu 1 of pop up button 3 of sheet 1 of window "Keyboard & Mouse"
    delay 1
    click pop up button 4 of sheet 1 of window "Keyboard & Mouse"
    click menu item 3 of menu 1 of pop up button 4 of sheet 1 of window "Keyboard & Mouse"
    click button "OK" of sheet 1 of window "Keyboard & Mouse"
    end tell
    end tell

    tell application "System Preferences"
    quit
    end tell

    (end of script)

    And here's the script I used to change it back to Mac layout:

    tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.keyboard"
    end tell

    tell application "System Events"
    tell process "System Preferences"
    click radio button "Keyboard" of tab group 1 of window "Keyboard & Mouse"
    click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
    click button "Restore Defaults" of sheet 1 of window "Keyboard & Mouse"
    click button "OK" of sheet 1 of window "Keyboard & Mouse"
    end tell
    end tell

    tell application "System Preferences"
    quit
    end tell

    (end of script)

    I saved the scripts as executibles with neat Apple and XP custom icons and put them in the Dock. Pretty slick.
  • ddsrocks Level 1 Level 1 (0 points)
    Hi,
    I was trying the script provided, but I get an error:

    "System Events got an error: NSReceiverEvaluationScriptError: 4"

    when it tries to run:

    click radio button "Keyboard" of tab group 1 of window "Keyboard & Mouse"

    Well, since I'm novice too to AppleScript, can you please help me finding out what's wrong?

    Thanks!!!
  • Michael Henley Level 4 Level 4 (1,895 points)
    Launch /Applications/AppleScript/AppleScript Utility.app and check Enable GUI Scripting.