do shell script >> show results

No problem! From a thread at MacOSXHints.com:


do shell script "sudo diskutil repairPermissions /" password "pword" with administrator privileges

This runs repair permissions on your “/” directory (startup disk). Just replace pword with your password.

Yup, that’s the script that I used the keychain for. I added error checking and a log file and it seems to work quite nicely. :wink:

– Rob

That sounds like a handy script template! Could you post the code here? I’ve thought about writing something like that, but never got around to Keychain scripting.

Here’s the entire script, in all its ugliness. You’ll need to tweak the keychain code to use a key that contains your admin password. The script assumes that the keychain name is the short user name for the current user (mine was named this way by default). It also assumes that the keychain is unlocked, but it will ask for the password if necessary.

set start_ to (current date) as text
set repair_perms to "sudo diskutil repairpermissions /"

with timeout of (1 * hours) seconds
	set result_ to (do shell script repair_perms ¬
		password my get_pwd() with administrator privileges)
end timeout
set finish_ to (current date) as text

try
	write_to_file("Start Time: " & start_ & return & "End Time: " & finish_ & return & return & ¬
		result_, ((path to desktop as text) & "Repaired Permission Report.txt") as text, true)
on error err number errNum
	try
		write_to_file("Error(s) occurred when attempting to write "Repaired Permission Report.txt"." & ¬
			return & return & "Error: " & err & return & return & "Error Number: " & errNum & return & ¬
			return & "Report Content: " & return & return & "Start Time: " & start_ & return & "End Time: " & ¬
			finish_ & return & return & result_, ((path to desktop as text) & "Error Report.txt") as text, false)
	end try
end try

to get_pwd()
	set keychain_name to do shell script "whoami"
	tell application "Keychain Scripting"
		tell keychain keychain_name
			set pwd_ to password of first key ¬
				whose name is "key name"
		end tell
	end tell
end get_pwd

to write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as text
		set the open_target_file to ¬
			open for access file target_file with write permission
		if append_data is false then ¬
			set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

– Rob