A while ago I posted a request for help to the OS X Applescript discussion area regarding GUI scripting the Repair Permissions option in Disk Utility. No responses though, and so I struggled on. Recently, lots of people have been asking that if I ever got it sorted out, would I share the code? So in the interest of making this job easier for other users, I'll post this. It's a little long, but here are the two options that I came up with.
You do not have to use GUI scripting though, you can just use the 'do shell script' command in a basic AppleScript application:
do shell script ¬
"sudo diskutil repairPermissions /" password "pword" with administrator privilegesThis is assuming that you have an 'admin' account and you replace "pword" with your admin password. You can then use cron to schedule the application to run. I have this set to run overnight when I'm not using my Mac. A drawback of this, though, is that there is no user feedback while the task is running.
My OS X partition is called 'MacOS HD' (highly original I know.) The following is the main code that I have attached to a Studio application:
tell application "System Events"
activate
end tell
tell application "Disk Utility"
activate
end tell
tell application "Finder"
set x to name of every process
if x contains "Disk Utility" then
tell application "System Events"
tell process "Disk Utility"
activate
set frontmost to true
get static text of row 2 of outline 1 of scroll area 1 of window ¬
"Disk Utility" of application process "Disk Utility" of application "System Events"
set x to the result
if x = {static text "MacOS HD" of row 2 of outline 1 of scroll area ¬
1 of window "Disk Utility" of application process ¬
"Disk Utility" of application "System Events"} then
select row 2 of outline 1 of scroll area 1 of window ¬
"Disk Utility" of application process "Disk Utility" of ¬
application "System Events"
tell window "Disk Utility"
tell tab group 1
click radio button "First Aid"
end tell
end tell
tell application "System Events"
tell process "Disk Utility"
set frontmost to true
if button "Repair Disk Permissions" of group 1 of tab group ¬
1 of window "Disk Utility" of application process ¬
"Disk Utility" of application "System Events" exists then
click button "Repair Disk Permissions" of group 1 of tab group ¬
1 of window "Disk Utility" of application process ¬
"Disk Utility" of application "System Events"
end if
end tell
end tell
end if
end tell
end tell
else
tell application "Disk Utility"
activate
end tell
delay 20
tell application "System Events"
tell process "Disk Utility"
set frontmost to true
get static text of row 2 of outline 1 of scroll area 1 of window "Disk Utility" of ¬
application process "Disk Utility" of application "System Events"
set x to the result
if x = {static text "MacOS HD" of row 2 of outline 1 of scroll area 1 of window ¬
"Disk Utility" of application process "Disk Utility" of application "System Events"} then
select row 2 of outline 1 of scroll area 1 of window ¬
"Disk Utility" of application process "Disk Utility" of application "System Events"
tell window "Disk Utility"
tell tab group 1
click radio button "First Aid"
end tell
end tell
tell application "System Events"
tell process "Disk Utility"
set frontmost to true
if button "Repair Disk Permissions" of group 1 of tab group 1 of window ¬
"Disk Utility" of application process "Disk Utility" of ¬
application "System Events" exists then
click button "Repair Disk Permissions" of group 1 of ¬
tab group 1 of window "Disk Utility" of application process ¬
"Disk Utility" of application "System Events"
end if
end tell
end tell
end if
end tell
end tell
end if
end tell
Let's just say that inspiration hit me early one morning after one too many cups of coffee. Hope this helps!
Mac OS X Hints
http://hints.macworld.com/article.php?story=2003031115282675