In OS X 10.4 I really wanted to find a way to script the keyboard shortcuts, since I administer a lot of Macs and spend a long time typing these keyboard shortcut changes on each machine – not fun. I would love it if anyone could suggest a way to automate this, using Applescipt or terminal. (Or, setting up one file and moving it, but that doesn’t seem to work either.) Could anyone give me suggestions on how this might be possible, with all the “improvements” to Applescript in 10.5?
Model: Mac Pro
AppleScript: 10.5
Browser: Safari 523.10
Operating System: Mac OS X (10.4)
Hi, what I am trying to get is, a way to define custom keyboard commands. For example, Safari is much better with command + ~ defined to the “Select Next Tab” menu, so I can cycle through my tabs as I do with windows in other apps. Since Menu Master broke (a really good haxie), there’s no easy way to set these commands on the fly other than to open the Keyboard control panel, choose Keyboard shortcuts, and type, type, type them all in. Multiply by several computers, and it becomes a real problem. So I was wondering if this process could be automated any way.
If the computers have the same system version and configuration,
I would try to make all the changes on one computer and then copy the file ~/Library/Preferences/com.apple.symbolichotkeys.plist to the others
If you save the below script as an Application Bundle, and then go into the “Resources” folder of the script application and copy the “com.apple.symbolichotkeys.plist” file into that folder, you can run this script on each computer and it will install the file in the right place. A self-contained little installer basically.
set PathToUser to path to home folder as text
tell application "Finder"
activate
try
set outFolder to folder (PathToUser & "Library:Preferences:")
duplicate file ((path to me as text) & "Contents:Resources:com.apple.symbolichotkeys.plist") to outFolder as alias
end try
end tell
Model: G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Matt-Boy, that script is pretty cool, I’ve never used bundles before. Thanks for the explanation. Unfortunately I am not sure that replacing the preference file in the library/preferences in my home folder works to redefine all the keyboard shortcuts, since the script didn’t end up doing anything, and manually copying the preference file and rebooting didn’t do anything either. Is there a way to verify that this works? Do I need to “authenticate” the prefs file or anything? Is this right right file, or am I perhaps supposed to do something with the Library/Prefs in root?
the problem is, the script throws an error, because the file already exists.
the try block ignores the error silently and nothing happens
Try this, I use the path to resource command, which is only available in Tiger and Leopard
try
set R to "com.apple.symbolichotkeys.plist"
set sourceFile to path to resource R
set m to modification date of (info for sourceFile)
tell application "Finder" to duplicate sourceFile to (path to preferences folder) replacing yes
if modification date of (info for ((path to preferences folder as text) & R) as alias) is m then
display dialog "Resource file '" & R & "' successfully restored"
else
display dialog "Resource file '" & R & "' couldn't be restored"
end if
on error
display dialog "Resource file '" & R & "' couldn't be found"
end try
Unfortunately after testing either manually copying that preference file to other computers with all applications quit then restarting, as well as using the above script, I’ve come to the conclusion that OS X is “picky” about letting us assign keyboard commands this way – it’s probably related to the way plists are set up, perhaps the codes that work to change “Paste and Match Style” in one OS X install don’t match up with another machine, or something.
Anyway, I am trying to do it the brute force way, i.e. with UI system events and good old Extra Suites. So I’d like to ask for help if I could.
Here’s what I’ve got so far:
tell application “System Preferences”
activate
tell application “System Events”
tell application process “System Preferences”
tell window 1
click button “Show All” of group 1 of group 2 of tool bar 1 (* in case another pane is already open )
end tell
tell application “System Preferences”
– reveal anchor “keyboardTab” of pane “com.apple.preference.keyboard”
reveal anchor “shortcutsTab” of pane “com.apple.preference.keyboard”
end tell
tell window 1
click button “+” of group 1 of group 1 of tool bar 1 ( in case another pane is already open *)
end tell
end tell
end tell
end tell
The script doesn’t work since I’ve got the wrong idea with how to select the + (add shortcut) button. My question is, how does anyone know, short of meditating, what the names of these UI elements are, and how to refer to them correctly (group 1 of tab 1 of tool bar 1 of planet earth). I need to find the UI names for that button, at least, and I think I can simulate the rest.
Can anyone help me find how to address that button, and recommend a tool for opening the UI elements of a program in the future?
Update. I’ve learned that Automator is 1000% better than it was before, and is able to “watch” me do these changes for my system in a way that I can save and run on other machines. So it seems that this is the simplest answer to my problem. I’d still like to know how to find those darned UI element names just on general principle if anyone can help