I’m trying to write a script that normalizes a bunch of stuff for a lab at the university I work for. I was wondering if anyone knew of a way to script the dock.app directly. By this I mean, not going in through system preferences and changing it that way. I want to be able to set the size and magnification to a certain place every time the student user logs in. I’ve been using UI Scripting so far, and I got this:
click menu item "Dock" of menu "View" of menu bar 1
delay 1
set value of slider 1 of window "Dock" to 0.65
set value of slider 2 of window "Dock" to 0.1
This works fine, but it has to open the sys prefs window which I’d rather it not do.
Here’s an example that I happened to have around. It will change the orientation of the Dock by modifying the Dock’s preference file/plist.
-- Close System Preferences if open to avoid issues when writing to plist
tell application "System Events" to set prefPaneExists to exists process "System Preferences"
if prefPaneExists is true then
tell application "System Preferences" to quit
end if
-- Modify the plist and quit the Dock, forcing it to read the new settings. It will relaunch automatically.
set new_dock_orientation to do shell script "defaults write com.apple.dock orientation bottom" -- top (unsupported in pref pane), bottom, left, right
tell application "Dock" to quit
-- Open System Preferences if closed by script - just being nice to the user.
if prefPaneExists is true then
tell application "System Preferences" to run
end if
For more info on the shell’s ‘defaults’, open Terminal and run: man defaults
You can also read the plist to get an idea of what it contains.
set dockPrefs to do shell script "defaults read com.apple.dock"
Thanks for getting me on the right track with that idea. That script you wrote changes the dock position just like you said. I have a little bit of an issue though. I read the man defaults stuff, and I did read com.apple.dock to see the variables. So here’s the problem, I pulled out the changing line that you gave me and edited it slightly to this:
do shell script “defaults write com.apple.dock tilesize 16”
tell application “Dock” to quit
now I have done “defaults read com.apple.dock tilesize” and determined that it should be the variable which controls the size of the dock. When i run that script it doesn’t change the size of the dock, even though the variable has been changed. I think the variable needs to be between 16 and 128 or at least thats the range that the operating system allows you to change it to outside of the terminal. I made sure not to have system preferences running when i ran the script. Do you think it might be a different variable? Do you know of a place/site where I can see the variable list for such things and what they do?
I also tried to edit directly from terminal and kill the dock.app but that didn’t work out either.
I don’t know of a source of info for this. I wonder if the dock will work only with specific sizes within a predetermined range. I’ve not messed with it and only had the code laying around for reference in the event that I ever wanted to script the dock.
do shell script "defaults write com.apple.dock magnification -boolean false"
do shell script "defaults write com.apple.dock tilesize -int 16"
tell application "Dock" to quit
all I had to do was specify what kind of data type it was. Your script uses a string when it sets the orientation and string is the default data type. Giving a string to an int or a bool wasn’t the way to go. There are a bunch of other variables in there, so guessing what kind each one is shouldn’t be too hard. Maybe you can get some use out of this finding.
Thanks alot for setting me in the right direction. It just took alot of pouring through a myriad of o’reilly manuals to find the so-called white rabbit(“Mac OS X for Unix Geeks” rules!)