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


Click here to return to the 'A simpler, more versatile solution...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A simpler, more versatile solution...
Authored by: macfreek57 on Feb 24, '08 08:17:58PM
I know this is old, but I found this and was looking for something a bit simpler. I edited down the original script. Now you can attach it to any folder through Folder Actions, and it will instantly change the ownership on any files added to it. When it executes, it will alert you via dialog box of the folder the script was executed from and the affected files.

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	
	-- This is the POSIX command to be executed.
	-- You can actually change this to any command you want to perform on the files as long as the format of the command requires a file name at the end.
	set shell_script to "chmod -R -f 777 " -- Don't forget to leave a space before the end quotation mark.
	
	tell application "Finder" to set the folder_path to the POSIX path of this_folder
	set alert_message to "A Folder Action has been executed from the folder " & folder_path & ". The following shell script was performed on the files that were just added to that folder:
	" & shell_script & "

Affected files:"
	
	set i to 0
	repeat with this_item in added_items
		set i to i + 1
		set posix_path to POSIX path of this_item as string
		
		do shell script shell_script & quoted form of posix_path -- Perform command
		
		set file_name to items ((length of folder_path) + 1) thru ((length of posix_path) - 1) of text items of posix_path as string
		set alert_message to alert_message & "
		" & i & ") " & file_name
	end repeat
	
	-- Alert user that permissions have been changed on the added files.
	-- This can be deleted or commented out if desired
	display dialog alert_message with icon 1
	
end adding folder items to
I wanted the files to be read-and-writable to everyone, but you can change this by changing the number "777" to something else. Google around if you don't know what to change it to. You can also use this script to perform any command line action as long as it uses the same format (i.e. command, options, then file name). All you need to do is change the string on the line
set shell_script to "chmod -R -f 777"


[ Reply to This | # ]