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


Click here to return to the 'An AppleScript to modify user permissions' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to modify user permissions
Authored by: jakacmar on Mar 12, '05 03:23:43AM
I haven't tested the script but just in reading it over I'm at a loss for how it actually works, or maybe I'm just confused about what it's actually trying to do. Needless to say, the script uses "sudo" in all of the shell scripts it runs but it never gets the password for an admin account so how could "sudo" actually work. Also, last I remember, "sudo" doesn't work at all using AppleScript and "do shell script". Instead you use something like:
 do shell script "whatever" with administrator privileges password "mypassword"
You could of course have a dialog pop up asking for the admin password instead of hard coding it in, but either way, it's needed at some point. Is this only for working on files that you already own? And if so, why use "sudo" at all? I'm definitely confused.

[ Reply to This | # ]
An AppleScript to modify user permissions
Authored by: qwerty denzel on Mar 15, '05 10:09:15PM
I am guessing that using sudo only works for those that have used it before (in Terminal).
do shell script "ls"
and
do shell script "sudo ls"
have different results for me like in the Terminal so I guess it works. On my computer I am of course an administrator, this script is not useful

[ Reply to This | # ]
An AppleScript to modify user permissions
Authored by: qwerty denzel on Mar 16, '05 10:15:19PM
Sorry, I cut myself off there. On my computer I am of course an administrator, this script is probably not useful to those who have a standard user account, since they can only change the permissions of their own files. Here is another script that changes the permissions of all items in your users folder.

property excluded_items : {"Public", "Sites"}

tell application "System Events"
	set currentUser to quoted form of (name of current user as string)
end tell

set this_folder to (path to home folder) as string
tell application "Finder"
	set these_files to every item of folder this_folder
end tell
repeat with i from 1 to the count of these_files
	set this_file to (item i of these_files as alias)
	set this_info to info for this_file
	set this_name to name of this_info
	if this_name is not in excluded_items and alias of this_info is false then
		set this_POSIX to quoted form of POSIX path of this_file
		try
			do shell script "sudo chown -R  " & currentUser & ":" & currentUser & " " & this_POSIX
		end try
		try
			do shell script "sudo chmod -R 775 " & this_POSIX
		end try
	end if
end repeat
Note the first 'do shell script' has:
"sudo chown -R  " & currentUser & ":" & currentUser & " " & this_POSIX
instead of:
"sudo chown -R  " & currentUser & ":admin " & this_POSIX
which is used in the original hint.

[ Reply to This | # ]