Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use GUI Scripting to script the Repair Permissions function System
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 privileges
This 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.

A nicer option is to use Applescript Studio.

[robg adds: The remainder of the hint contains an AppleScript snippet than can be used to build an AppleScript Studio application. It is not a complete application. I haven't tested the script, but I have checked that it survives a syntax check in AppleScript. You will need the GUI Scripting addition installed in order to compile the script.]

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!
    •    
  • Currently 1.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[17,307 views]  

Use GUI Scripting to script the Repair Permissions function | 1 comments | Create New Account
Click here to return to the 'Use GUI Scripting to script the Repair Permissions function' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use GUI Scripting to script the Repair Permissions function
Authored by: billbarstad on Mar 23, '03 02:55:48AM

I haven't used Xjanitor, nor need I. I've used Macaroni for over a year and I never have to think about maintenance, as it runs the maintenance scripts automatically.



[ Reply to This | # ]