Finder Set Folder/File Ownership

I have a number of scripts that create new folders and others that add files to existing folders. Because some of my scripts can take hours to run, I run them under a second account on my Mac Pro. That way I’m not bothered by the scripts opening and closing windows. Also, since some scripts use System Events, my typing doesn’t interfere with their proper operation. To enable this I have a folder used by both my main account and my secondary account. For a number of reasons, I can’t use the shared folder on my main drive.

Now to make this special shared folder work, both accounts belong to a User Group named “New” and everything in that folder should have the same ownership. When the folder was small I could reset ownership globally using Finder’s Get Info window to apply the privileges to all enclosed items. HOWEVER, there was a side effect – Time Machine treats all these files with privilege changes as new to be backed up. What I needed was the ability to change ownership of a file or a folder and all its contents to the “New” group inside the AppleScript that created it. I first tried using AppleScript to change the ownership properties in Finder, but I couldn’t make that work.

Here is what worked for me. For some reason the chown command does not work with my User Group “New” by name, but the group number 505 works just fine. Go figure! The path names in both subroutines must be strings.


on set_ownership_for_file(file_path_name)
	set this_POSIX to quoted form of POSIX path of (file_path_name as alias)
	do shell script "chown -R  " & "Programming:505 " & this_POSIX user name "Programming" password "xxx" with administrator privileges
	do shell script "chmod -R 770 " & this_POSIX user name "Programming" password "xxx" with administrator privileges
end set_ownership_for_file

on set_ownership_for_folder(folder_path_name)
	tell application "Finder" to set these_items to every item in folder folder_path_name
	set this_POSIX to quoted form of POSIX path of (folder_path_name as alias)
	do shell script "chown -R  " & "Programming:505 " & this_POSIX user name "Programming" password "xxx" with administrator privileges
	do shell script "chmod -R 770 " & this_POSIX user name "Programming" password "xxx" with administrator privileges
	repeat with this_item in these_items
		set this_POSIX to quoted form of POSIX path of (this_item as alias)
		do shell script "chown -R  " & "Programming:505 " & this_POSIX user name "Programming" password "xxx" with administrator privileges
		do shell script "chmod -R 770 " & this_POSIX user name "Programming" password "xxx" with administrator privileges
	end repeat
end set_ownership_for_folder