automator: shell script to change file permissions

Hey guys,

Just created a workflow to copy some files from one location to another.
Second thing I want to do is run a shell-script to set some file permissions recursively, some for the folders, the other for the files.
I figured I could do the following:

-----
cd /IntoAFolder
find . -type d -exec chmod 770 {} \;
-----

Unfortunately, this seems to be needed to be done as a sudo'er and thus requires the user's password.

So the question is, how do I get that password and hand it to the shell script or is there another way of doing this?

MacBook Pro (early 2006), Mac OS X (10.5.3)

Posted on Jun 8, 2008 9:48 AM

Reply
14 replies

Jun 8, 2008 10:26 AM in response to daenneys

Putting an admin password in a script isn't usually a good idea, but chmod doesn't need a password if you are owner of the file - what are you trying to do? If it is just something like setting permissions for a file you are dropping in a public folder, you can use an AppleScript action to tell the FInder to set the owner privileges, group privileges, and/or everyones privileges properties, for example:

tell application "Finder" to set everyones privileges of (choose file) to read write

Jun 8, 2008 10:31 AM in response to daenneys

What I want to do is recursively chmod the subfolders and files of a "root"-folder.

The way I know to do so is:

cd /root-folder
find . -type d -exec chmod 755 {} \;

That will chmod all subfolders from the root-folder to 755.
Next i want

find . -type f -exec chmod 644 {} \;

That will chmod all subfiles fromn the root-folder to 644

Unfortunately, find gives me a permission denied when I run this command from the command-line. When I just manualy chmod everything that works fine but is a bit to much work when it comes down to a tree of 5 subfolders and 120 files.

Waht basically hapens:
The user selects a bunch of folders.
Then they are copied to /Applications/RCT3.localised/Data/Styles/Themed

and then I need to chmod them just to be sure, as sometimes stuff break along the way if you don't

Jun 8, 2008 11:44 AM in response to daenneys

Figured it out, my tester screwed up his file permissions, doh :/

I have a second question though.

Say that folder I'm trying to chmod contains some folders owned by me and some by someone else. Obviously you can only change the permissions on the ones you own, but how do you tell that to Automator?

as in
find . -type d -exec chmod 755 {} \; but only for files I own?

Jun 8, 2008 12:15 PM in response to daenneys

Hmm, doesn't seem to be other than using AppleScript. I tried deleting the text in the Cancel button, but Automator just gives an error when the workflow is run.

On the other hand, you could use the action "Wait for User Action" instead. It just has a Continue button. Is that helpful, or did you need something more than a message?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

automator: shell script to change file permissions

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.