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?

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

Similar Messages

  • Permz - Quickly change file permissions in any file manager

    Designed to be integrated into any file manager, permz is a bash script which presents a GUI menu.  You can use it to quickly change file permissions and ownership as a normal user or as root, and delete files as root.  I wrote this because I have yet to see a file manager that isn't cumbersome for this - the mechanism is usually buried on a second tab of the Properties window, and changing permissions often involves multiple clicks in a grid. To change the owner of a file, you need to type the username. And if the file is owned by root, you can't do anything.
    permz --help
    Presents a GUI menu for changing file permissions/ownership. May be run
    as a normal user or root.
    Requires: zenity gksu
    Optional: sudo (recommended to prevent multiple root password prompts)
    Usage: permz FILE [...]
    MENU FUNCTIONS:
    rwxrwxrwx Sets file(s) to given permissions
    Sticky Clear/Set Performs "chmod -t" or +t to clear or set the sticky
    bit. You may select to clear/set sticky in addition
    to changing other permissions.
    Recursive go-rxw "chmod -R go-rxw" on file(s) recursively, denying
    access to non-owners
    Recursive go-w "chmod -R go-w" on file(s) recursively, denying write
    to non-owners
    Recursive ugo+rX "chmod -R ugo+rX" giving read access to all. Also
    sets +x for directories and executables.
    Recursive ugo+w "chmod -R ugo+w" on file(s), giving write to all
    (You may select several compatible recursive functions above at once)
    Owner USER As ROOT Sets ownership to USER:USER as root
    DELETE As ROOT Deletes file(s) as root. Must be used alone or with
    "Perform Recursively" (to delete directories - USE
    WITH CAUTION). Not available if permz is run as root.
    Perform As ROOT Run as root to change selected permissions.
    (Use of root is automatic when changing ownership)
    Perform Recursively Adds -R to all chmod, chown, and delete commands to
    descend into subdirectories. Use in conjunction with
    any other functions. (Recursion is automatic for
    "Recursive" functions above)
    Current su command is set to: gksu -gS
    If you're somewhat familiar with bash, adding additional options or changing the existing ones is straightforward.
    I have tested it pretty thoroughly but if you do encounter anything amiss please let me know.
    More details at http://igurublog.wordpress.com/downloads/script-permz/
    And in the AUR at http://aur.archlinux.org/packages.php?ID=36978
    Instructions for integrating permz into PCManFM-Mod are here.
    Last edited by IgnorantGuru (2010-05-05 13:53:08)

    rransom wrote:Recursive ugo+rX would be more useful than "Recursive ugo+r (dirs +x)".  (The +X feature of chmod is available at least in GNU coreutils, FreeBSD, and POSIX 2003.)
    Done - thanks for the tip.  I also left the old code active in there with just the menu option disabled, so if anyone wants it the other way or wants both it's easy to enable.  The difference is that the old way won't make any files +x, just dirs.
    permz doesn't provide every possible setting of permissions, just common ones, so you may want to customize it.  But I used to have these as user actions when I used Krusader and I found these were the handy ones, at least for me.

  • How do I stop DW CS6 randomly changing file permissions via FTP?

    How do I stop Dreamweaver CS6 12.0.1.5842 randomly changing file permissions when it uploads files to my web server via FTP.
    I can no longer trust Dreamweaver to upload websites correctly as it changes permissions on some files which then deny the server access to the file which in turn makes the webpage unreachable/return a 403 error.
    This is driving me insane.
    I'm using an early 2011 Macbook Pro 10.7.5.

    Hi,
    I'm having this problem too. Has Adobe fixed the issue yet? This appears to be an Adobe problem, not all the web hosts out there. CS6 is ramdomly (meaning: not every time) changing permissions on files uploaded with it and is not usable for web work until this problem is fixed by Adobe or a solution is provided. If I wanted to use a separate FTP program I would not have recommended that my employer buy multiple Adobe CS6 product licenses. One of the primary appeals of DW is the integration of FTP into the workflow.
    I am using a destop iMac2.8 GHz Intel Core 2 Duo, 4 gigs of 800 MHz DDR2 SDRAM.
    OSX 10.7.5
    I am using DW Version 12 Build: 5808
    Dreamweaver CS4 that I was using until this new purchase was working just fine. No file permisssion changes. I am being forced to go back to using it until Adobe posts a fix for this.
    I should ask while I'm here: has anyone found a solution for this yet?
    Thanks,
    -c-

  • Changing File Permissions via FTP for WordPress

    Hi,
    I access files for a WordPress installation via FTP and when I try to change permissions to some files for some plugins compatibility issues I get the error below and the permissions are not applied.
    SITE CHMOD 747 colors.css
    Response: 500 'SITE': command not understood
    Best Regards,
    Abby Doc

    Hello Abby,
    Thanks for posting here.
    I would like to know how you're trying to change File permissions. Is that by using FileZilla or something?
    I would suggest you to refer the below links.
    Related Thread:
    http://social.msdn.microsoft.com/Forums/windowsazure/en-US/50e94a19-066b-443e-a70a-4fe3d99a6e95/how-to-set-file-permissions?forum=windowsazurewebsitespreview
    http://wordpress.org/support/topic/chmod-aka-file-permissions
    Steps to change a directories File Permissions using FileZilla FTP.
    Stop your website from the management console (https://manage.windowsazure.com)
    Open up the FTP site in Filezilla
    Rename the directory that has the problem
    Restart your website.
    I hope that helps.
    Best Regards,
    Sadiqh Ahmed

  • Changing file permissions

    Hi, does anybody have any idea how to change file permissions on a apache server. I have created ftp app that transfers file from a computer to a server and I need to change the file permissions to 0777. I'm using FileTransferClient from enterprisedt.
    Cheers
    Edited by: Ash3003 on Dec 10, 2008 2:24 AM

    Hmm ok, im a little bit lost. The server is running a pretty complicated video broadcasting site that I dont have much to do with. the app im making encodes videos and uploads them to a import directory on the server. From there some type of program accepts them and puts them in the sites playlist. The problem is the program that accepts them has to have the permissions set to 0777 before it recognizes them. My app doesn't run on the server it only get files there. And as far as i know these are the only files that need the permissions to 0777. by changing the unmask on the server will that effect other files on the site.

  • Use applescript w/automator to change files permissions

    Hi, I need to change permission to several files to Read and Write to the Owner, Staff and everyone. I do this everyday, that's why I need someway to automate this action. I don't know about scripting but I do know (more or less) how to create a service in Automator. I am looking to create a service in automator which runs an applescript that changes this file's permissions. I need this to be applied to all sub folders and subfiles. Any clue what the applescript should say? Thnx

    Perfect! It worked perfectly even though I didn't understood the difference between the first shell script and the other. I've tried both, and they both did the same thing: They changed the Owner, the Staff and Everyone to Read and write.
    For my tests, this is what I did (for the sake of all the non geeky guys like me who needs this):
    I opened Automator and choose to make a Service, and set it to Files and Folders in Finder.
    Then I added the finder action "Get selected finder items".
    Then added "Run shell script" and did what you told me, and that's it!
    Thanx for your time

  • Automator Shell Script

    Hi,
    I am very new to Automator and know the very basics about Unix but use Terminal frequently for very repetitive tasks (which I usually find on the web) - one of which is creating MD5 of all files within a specific folder. To achieve this I generally open Terminal, go to a specific project folder and enter: find . -print0 | xargs -0 -I{} md5 "$@"{} >> md5.chk
    This then creates a txt file called md5.chk within the folder which lists all off the files within that folder (with file path) as well as all the the associated checksums for these files.
    I would like to streamline this process a little by creating a service with Automator so I can select a Folder within Finder and select the require Service.
    Unfortunately I am not getting very far. This is where I am:
    1. Open Automator and select Service
    2. Add "Get Specified Finder Items" action
    3. Add "Run Shell Script" action (Pass input: as argument) with the following: find . -print0 | xargs -0 -I{} md5 "$@"{} >> md5.chk
    Unfortunately this doesn't achieve the required result. I presume there are some elements within the shell script that I am simply missing. Can anyone help?
    Thanks

    This is a test. It is ONLY a test.
    Change your Automator "Run Shell Script" to:
    ( pwd
    echo "+++++"
    /bin/ls -dlae0@ .
    echo "+++++"
    id -a
    echo "+++++"
    echo "number of args: $#"
    echo "+++++"
    printenv
    echo "+++++"
    echo find "$@" -type f -print0
    echo "+++++"
    find "$@" -type f -print0 | xargs -0 -I{} echo "{}"
    ) >/tmp/tmp.txt
    Then look at /tmp/tmp.txt and see if the expanded command look they it should. You can get to the /tmp directory using Finder -> Go -> Go to Folder -> /tmp
    The double-quotes will be missing (as the shell will swallow them), however, what you are interested in is did the "$@" expand to the desired directory.
    The pwd will tell us what the current working directory is. This could be important, as maybe you do not have permissions to use that directory.
    The /bin/ls will tell us the ownership and permissions of the current working directory.
    The id -a will tell us what account the automator script is running as
    The $# will tell us how many arguments were passed as part of the "$@"
    The printenv will tell us what environment variables have been set.
    The find|xargs is changed to replace md5 with echo, so that we can see that the "{}" expanded to.

  • Writing a shell script to move files

    Hello,
    I'm trying to write a shell script that will move files from one directory to another at a time specified by me. I've got a similar script attached to an Automator action, which is triggered nightly by iCal.
    Of course, this one simply deletes files that are older than a day in a couple of locations. I'd like to have another that MOVES files and folders from one location to another. So far, I've come up with this:
    find /Volumes/Location/01/* -type d -or -type f -mtime +7 -exec mv -f /Volumes/Location/01/* /Volumes/Location/02/ ;
    Which just about works, but it actually seems to be moving all the files that are LESS than a week old. Any and all suggestions are appreciated, as I'm a total n00b here.

    find /Volumes/Location/01/*
    -type d -or -type f -mtime +7
    -exec mv -f /Volumes/Location/01/* /Volumes/Location/02/ ;
    Which just about works, but it actually seems to be moving all the files
    that are LESS than a week old. Any and all suggestions are appreciated,
    as I'm a total n00b here.
    your -exec is not selecting the files or directories found by the 'find' command.
    It is moving everything in /Volumes/Location/01/*
    Looking at "man find", I think you want your -exec to be
    -exec /Volumes/Location/01/{} /Volumes/Location/02/ ;
    As red_menace has pointed out, you have to change your -type options
    so that you select directories or files.
    You may also want to include -prune so that you do not decend
    into subdirectories.
    While the following is untested, I might write the command like this:
    find /Volumes/Location/01/*
    -prune -mtime +7
    ( -type d -or -type f )
    -exec mv -f /Volumes/Location/01/{} /Volumes/Location/02/ ;

  • Unix shell script to batch file for windows

    Hello all,
    Iam writing a program in java in unix environment and iam executing using shell scripts in unix this program is for client-server environment
    which look like this:
    For server:
    #! /bin/ksh
    export CLASSPATH=/user/vpp/jal/classes:$CLASSPATH
    #set var for filename config file
    export JAL_CONF_FILE=/user/vpp/jal/conf/JALapp.conf
    java -DJAL_CONF_FILE=$JAL_CONF_FILE jalsvr/JALTCPServer 7776for client side it is
    #! /bin/ksh
    export CLASSPATH=/user/vpp/jal/classes:$CLASSPATH
    echo $CLASSPATH
    java jalcl/JALTCPClient msoc05:7776my question is know i want to execute them in windows by creating batch files runsvr.bat, runcl.batbut how
    i gave PATH by giving JRE path but what is the replacement of export because iam having all class files
    in /jalcl for clients and /jalsvr for server but want to create this batch file in separate /bin folder how to do.please help me

    Thank you for reply ,
    And sorry by mistake question repeated twice,
    but when iam executing those batch files it is throwing some exceptions,
    in that file you did not mention to set the JRE path whether it is not necessary and also there msoc05 is the machine name of unix system that need to kept or need to be changed with window IP address .please reply.
    thanks in advance.

  • Help 'Exiting' after Automator Shell Script Execution

    Hello,
    I've recently installed and got running GCalDaemon (http://gcaldaemon.sourceforge.net/) which allows me to Synch Rainlendar <-> Google Calendar through iCal (You can also synch iCal <-> Google Calendar). I needed to start up a shell script/applescript after each startup/login in order for GCalDaemon to start the synching process each time and continue to do so at the timed intervals. I would do so by the following terminal code:
    cd /usr/local/sbin/GCALDaemon/bin
    ./standalone-start.sh
    I then tried automating this process and came across shell script execution through Automator. I did so and created a .app with the above mentioned code. This works and it starts up the necessary .sh file I need and the snyching works under StartUp. My concern is however, how do I exit terminal once the code has executed the necessary file? All I have in my .app is the above mentioned code for now. I just need it to exit terminal because on startup or after starting the program, I get this issue (See Attachment)
    This continues to run, so my guess is that I need to add code to exit terminal and allow the .app to close itself properly after doing so.
    Please guide me in the right direction.
    Picture Belows shows what happens when I run the Automator App. It continues to run until I quit out of the app manually (TheGCal programs works fine though). I feel I need to have app quit Terminal or fully end the process and quit out on it's own.
    Thanks
    <table style="width:auto;"><tr><td></td></tr><tr><td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From GCalDaemon</td></tr></table>

    i redirected the command output to /dev/null which is unix equivalent of a black hole and I also redirected error output to standard output in case the script produces any errors.
    also & at the end tells it to continue without waiting for the script to finish.
    Message was edited by: V.K.

  • Trouble running automator shell script

    This is probably going to be an really simple fix, but I'm have trouble building an automator service that runs a bash shell script. All of the elements of the script work fine when plugged into shell, but for some reason the automator service is failing to run. The script calls ffmpeg to convert an audio file:
    for f in "$@"
    do
      fn="${f%%.*}"
      /Users/aa/Applications/ffmpeg/ffmpeg -i "$f" -acodec libmp3lame -q:a 7 -ar 8000 -ac 1 "$fn.mp3"
    done
    The script runs fine without the ffmpeg command, and the ffmpeg command runs fine in the terminal on its own. Where's the error coming from?
    Thanks!

    The first is what I'm getting from the bash terminal execution, the second from automator. I'm accenting the differences I see. Thanks for the help!
    ----bash----------------------------------------
    drwxr-xr-x@ 67 aa  staff  - 2278 Apr  6 07:42 .
      com.apple.progress.fractionCompleted  14
    0: group:everyone deny delete
    uid=501(aa) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81( _appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),398(c om.apple.access_screensharing),399(com.apple.access_ssh)
    0
    -bash
    TERM_PROGRAM=Apple_Terminal
    SHELL=/bin/bash
    TERM=xterm-256color
    TMPDIR=/var/folders/x9/y4r_w7gj4_j_3wkfxn6s6fqm0000gn/T/
    Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.oSzc5cau0v/Render
    TERM_PROGRAM_VERSION=343.6
    TERM_SESSION_ID=AF09D92C-2CB4-4069-A172-0DE12EB226BD
    USER=aa
    SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.RFhFIs94Ad/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
    PATH=/Applications/anaconda/bin:/Applications/anaconda/bin:/Applications/anacond a/bin:/Users/aa/anaconda/bin:/Applications/anaconda/bin:/Applications/anaconda/b in:/Applications/anaconda/bin:/Applications/anaconda/bin:/Library/Frameworks/Pyt hon.framework/Versions/3.4/bin:/Applications/anaconda/bin:/Users/aa/anaconda/bin :/Applications/Anaconda/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbi n:/opt/X11/bin:/usr/local/git/bin:/usr/local/MacGPG2/bin:/usr/texbin
    PWD=/Users/aa
    LANG=en_US.UTF-8
    XPC_FLAGS=0x0
    XPC_SERVICE_NAME=0
    SHLVL=1
    HOME=/Users/aa
    LOGNAME=aa
    DISPLAY=/private/tmp/com.apple.launchd.YewceoE69R/org.macosforge.xquartz:0
    _=/usr/bin/printenv
    ----automator----------------------------------------
    /Users/aa
    drwxr-xr-x@ 66 aa  staff  - 2244 Apr  6 07:42 .
      com.apple.progress.fractionCompleted  14
    0: group:everyone deny delete
    uid=501(aa) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81( _appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),398(c om.apple.access_screensharing),399(com.apple.access_ssh)
    0
    SHELL=/bin/bash
    TMPDIR=/var/folders/x9/y4r_w7gj4_j_3wkfxn6s6fqm0000gn/T/
    Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.oSzc5cau0v/Render
    USER=aa
    SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.RFhFIs94Ad/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    PWD=/Users/aa
    XPC_FLAGS=0x0
    XPC_SERVICE_NAME=0
    SHLVL=1
    HOME=/Users/aa
    LOGNAME=aa
    DISPLAY=/private/tmp/com.apple.launchd.YewceoE69R/org.macosforge.xquartz:0
    _=/usr/bin/printenv

  • Automator "shell script" doesn't work

    Hi,
    I'm trying to build an Automator script in OSX 10.6.4.
    -Get selected items in the finder
    -Execute shell script (arguments)
    cd $(dirname "$1")
    for f in "$@"
    do
    /foo/bar/convert "$f" out.pdf
    done
    If I press the "execute" button, the script seems to work, as shown here: http://i.imgur.com/Nyhcd.jpg
    However, if I try to run the script by right-clicking on a file, a pop up message says that "the execute shell script has encountered an error"
    The "convert" command works flawlessy from a Terminal.app window, and the enviroment is correctly set-up in this way:
    export MAGICK_HOME="/Users/gipinet/image_magik/"
    export PATH=$MAGICK_HOME/bin:$PATH
    export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"

    Environment variables are NOT global. They are inherited from a parent process as a subprocess is created by that parent.
    .profile is ONLY read by the shell (bash) when you start a Terminal session. So only the shell and any commands it runs will see those environment variables.
    Since you are not running the Automator workflow from a Terminal session, there is no way for Automator to inherit those environment variables.
    So if those environment variables are needed for your convert utility, then you need to make sure that your Run Shell Script needs to get them on its own.
    You could hard code them into your Run Shell Script, or you could source your .profile
    . /User/yourusername/.profile # notice the . which is the /bin/sh 'source' command
    Of course if your .profile has lots of other stuff that will upset the Automator Run Shell Script, then you may not want to do that. For example, if your .profile were expecting things in its environment that ONLY exist in a Terminal session that might upset your .profile when invoked in Run Shell Script.

  • Automator shell script to zip

    I'm trying to follow some advice I found to use an automator Finder Plugin to zip selected files and save the zipped files. It's not working. Here's what I'm doing:
    1) Open Automator
    2) Under Libarary, select Automator.
    3) Drag Run Shell Script to Workflow window.
    4) Leave Shell = bin/bash, make Pass input = as arguments.
    5) Enter code:
    for f in "$@"
    do
    zip -r "$f" "$f"
    done
    6) Save As Pluging. Name = ZipClean, Plug-in for = Finder.
    7) Try it out... no joy. Select one file and right click to Automator -> ZipClean. It seems to go away for a bit of time and come back, but no new zip has been created (really, I searched!).
    I know this is a silly script but if I can get this version to work, I'm going to add -x *.DS_Store -x .svn in order to create zips that are not corrupted by osx and svn invisible files and directories.
    So bottom line... why isn't the zip file being created and stored? When I do this directly in a terminal window it seems to work ok.
    Thanks in advance!
    joe

    If you plug your shell script into Automator and use a Finder action to pass items to it, it works for a folder but fails for a single file. You might need to tweak the parameters for a plug-in - refer to the zip manual page. You can also use ditto (I posted an AppleScript action earlier using ditto in this reply).

  • Automator shell script won't run

    Hi,
    I'm putting together a little Automator app that opens whenever I double-click on an .exe file and opens that file with wine. So far, however, I've had little luck. I've created a shell script automator app with the following script:
    for f in "$@"
    do
              /usr/local/bin/wine "$f" &
    done
    Outside of Automator the script works just fine. However, as an Automator app it doesn't work at all; nothing happens, even though Automator tells me that that the workflow was successfully completely. What am I doing wrong?
    Thanks,
    Alex

    Automator uses /bin/bash as the shell.
    Running your script interactive has a different environment from running under Automator.  For one thing, stdin/stdout/stderr are pointing to a tty (actually a pseudo device /dev/pty).  Perhaps this is affecting how Wine us behaving.
    Other issues might be where your current working directory is located, or some environment variable (such as PATH) that is not the same under Automator that exists when running interactively.
    You might try capturing things like
    ( printenv
      pwd
      id -a
      echo "\$# $#"
    ) >/tmp/automator.environment

  • Shell Script to change filename.

    I'm need to use the Run Shell Script action to change a filename. Basically I need to drop the ".app" extension of an app on the desktop to get it to appear as a folder.
    I know I need to use:
    mv TemporaryApp.app TemporaryApp
    but am not sure what to use before this to get the shell script to recognize the file.
    Any help appreciated.
    Thanks,
    Kevin

    Thanks, John.
    But my requirement as follows,
    Is there a way to change user password using passwd command in shell script? I don't want to use expect. use the command passwd, it will ask for old password and then the new password twice.But I want to use it in a script without my interaction. I want to provide new password in a script a than run passwd to change user password. Problem of using passwd in shell script is that passwd requires user interaction to change password and script stops. My question was is there a way to use passwd without interaction or is there other way to change password using shell script.
    Thanks
    Ram

Maybe you are looking for