Permissions Folder Action

Hello! We have a Mac OS X 10.3.x environment and a shared network drive that has watched folders. When a user puts an item in the In folder it is processed by an application and put into and Out folder. The edited documents that are produced by the application come out with Read Only permissions for Group and Everyone. We need to attach a folder action to these folders so that when a new item is added, the permissions of that file will automatically be changed to Read/Write for Ower/Group/Everyone. I have a script that I have been trying and I have it installed in the Folder Actions directory and the script attached to the folder, but nothing ever happens. So the question is this, what is wrong with my script and, is there a way to target just new files or will the script only target the folder as a whole? Here is the script:

on adding folder items to this_Folder after receiving theAddedItems
	
	repeat with eachItem from 1 to number of items in theAddedItems
		set filePath to POSIX path of eachItem
		do shell script "chmod -R 777 " & quoted form of filePath password "AdminPassword" with administrator privileges
	end repeat
	
end adding folder items to

Thanks!
–PEACE–

try this:


-- change this to the path to your destination folder
property DestinationFolder : alias "Macintosh HD:Users:username:Desktop:destination:"

on adding folder items to this_folder after receiving added_items
	repeat with thisfile in added_items
		tell application "Finder"
			set owner privileges of thisfile to read write
			set group privileges of thisfile to read write
			set everyones privileges of thisfile to read write
			move thisfile to folder DestinationFolder
		end tell
	end repeat
end adding folder items to

cheers!!
howard

Sir Howard, has anyone told you lately just how much you rock!

–PEACE–

Addendum:

We have found that items changed in this way are sometimes ‘forgotten’ by AppleScript due to timing. As far as I can figure it works like this: When an item is added to the folder, the script is triggered and it takes a few fractions of a second for the script to start and a few more to wrap up… If an item or items are added to the folder while the script is already in progress, those items will just sit there un changed, as they cannot be added to the current script cycle and they will not trigger another script cycle since they now already exist within the folder. Removing the items and re-adding them to the folder can get the script runnign again, but what fun is it doing things manually?

That said, I have adjusted the above script so that those forgotten items are effected the next time the script is triggered… instead of the script changin just the new items in the folder, this version changes all files within the folder. This works great in my situation since the number of total files is never great, but if it is a folder where there are hundreds or thousands of files then an alternate method would be the recommendation.


on adding folder items to this_Folder after receiving added_items
	tell application "Finder"
		set owner privileges of files of this_Folder to read write
		set group privileges of files of this_Folder to read write
		set everyones privileges of files of this_Folder to read write
	end tell
end adding folder items to

–PEACE–

You could also do it this way - probably not the best way but still handy to know…


on idle
	try
		  tell application "Finder"
       set owner privileges of files of this_Folder to read write
       set group privileges of files of this_Folder to read write
       set everyones privileges of files of this_Folder to read write
   end tell	end try
	return 60 -- idle time, in seconds, between executions 
end idle

cheers
Howard

Thanks Howard… one question on this last one though… How do you get the script to run? Is it always running or is it a folder action? It looks like the kind of thing I need, but I just dont know how to hande an ‘on idle’ script… and where is my AppleScript in a nutshell book, has anyone seen my book? I swear it was right there on the shelf… oh well! Thanks!

–PEACE–

Hi
Basically I leave it running as a stay-open application - it does a couple of other things as well like refreshing the Finder windows to re-trigger any scripts that have stopped.
cheers
Howard

Help for a beginner please…
( I am running Leopard 10.5.7)

I have 2 folders. One is named ‘To be fixed’ and the other is named ‘To be filed’

I have compiled the below script and attached it to the ‘To be fixed’ folder using Folder Actions. Adding a file to the ‘To be fixed’ folder does nothing yet I am believing that the below script should be changing the permissions of the file and moving it to the ‘To be filed’ folder. And yes, I did change the destination folder so that the script would compile correctly. :slight_smile: What am I missing?


-- change this to the path to your destination folder
property DestinationFolder : alias "Macintosh HD:Users:username:Desktop:destination:"

on adding folder items to this_folder after receiving added_items
	repeat with thisfile in added_items
		tell application "Finder"
			set owner privileges of thisfile to read write
			set group privileges of thisfile to read write
			set everyones privileges of thisfile to read write
			move thisfile to folder DestinationFolder
		end tell
	end repeat
end adding folder items to

Hi,

defining a property with an alias is not recommended, the script won’t compile, if the path is not valid.
In this case a string path is sufficient.


property DestinationFolder : "Macintosh HD:Users:username:Desktop:destination:"

Have you saved the script in (~)/Library/Scripts/Folder Action Scripts ?

Because I was wanting for the system to verify my typing, it was kind of handy to have it compile only when my path did exist but I do understand the advantage of being able to create and compile a script for a path that does not exist on the current computer. Thanks for the pointer.

Silly me. I figured that the act of ‘Attach a Folder Action’ & ‘Configure Folder Actions…’ available in the Finder’s contextural menu would take care of that. I hadn’t expected to be able to attach an action that was not in an acceptable place.

'Tis working now and I’m so much more advanced now. LOL. Thanks a bunch for the simple fix.