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).

Similar Messages

  • How to avoid password prompt in shell script for zip password protection

    Hi
    I am trying to set password protection to my oracle database export backup. Once the backup completed, it should compress with a password protection. Thats the plan. Initialy we were using the gzip for the compression. Then realized that there is no password protection for the gzip. Started using zip option. I tried using
    zip -P <password> filename
    But it was throwing below error.
    -bash-3.2$ zip -P expreports REPORTS_2013FEB14.dmp
    zip warning: missing end signature--probably not a zip file (did you
    zip warning: remember to use binary mode when you transferred it?)
    zip warning: (if you are trying to read a damaged archive try -F)
    zip error: Zip file structure invalid (REPORTS_2013FEB14.dmp)
    Not quite sure why.
    Then I used zip -e REPORTS_2013FEB14.dmp.zip REPORTS_2013FEB14.dmp
    But this prompting for the password. As I am trying to put the command in the script. It will be tough if it prompts for the password.
    I would like to know how to avoid the password prompting by saving somewhere or how the code should be written. Tried using expect feature of shell script. Below was the code I tried. It didnt work.
    [oracle@SF40V6636 test]$ cat repexp.sh
    zip -e REPORTS_imp.log.zip REPORTS_imp.log
    expect "Enter password:"
    send "imprep"
    expect "Verify password:"
    send "imprep"
    So please help in avoiding this password prompt or let me know how to change the code.
    Thanks
    SHIYAS M

    How about using gpg and adding a secret key to the requirement of a password? No one should be able to decrypt your file, not by knowing only the password.
    1. Generate a public and private key pair:
    $ gpg --gen-key
    When it shows "We need to generate a lot of random bytes…" open another terminal session and type "dd if=/dev/sda of=/dev/null" to create traffic. When the public and secret key created and signed you can Ctrl-C the dd command.
    To see what you have created:
    $ gpg --list-keys
    2. Encrypt and gzip your stuff:
    $ tar zcf stuff.tgz file_or_folder
    $ gpg recipient "Some Name" encrypt stuff.tgz
    $ rm -f stuff.tgz
    3. Decrypt and extract the archive:
    $ gpg batch yes --passphrase "password" -d stuff.tgz.gpg > stuff.tgz
    $ tar zxvf stuff.tgz
    Again, knowing the password alone will not let anybody decrypt your stuff.

  • 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

    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.

  • 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 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

  • 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

  • Assistance with Automator Shell Scripting

    Is there a way to take the Ask for text, set the returned value as a variable and use that variable later on in a Shell Script action?
    Thanks in Advance

    This is showing how you would access your variables. $@ will contain all the command line variables and the for do loop intinerates over each one one at a time.
    So you would replace this with your script of course but thats how you would access the arguments.

  • Cron job is not working SCP automated shell script

    #!/usr/bin/expect -f
    # connect via scp
    spawn scp "[email protected]:/u04/dumps/test.dmp" /u10/app/
    expect {
    -re ".*es.*o.*" {
    exp_send "yes\r"
    exp_continue
    -re ".*sword.*" {
    exp_send "pwd\r"
    interact
    above is the automated script to download the file from remote server to local server.
    I am trying to download around 2GB file. for that i am using the above automated script. But that script is not working cron service.
    Cron is not executing that script to download the file from Remote server to Local Server.

    Cron is not executing that script to download the file from Remote server to Local Server.That script only or any script ? Did you try with something else ?
    I had a similar problem on a Linux machine, where cron jobs didn't start, and the only solution was to restart cron daemon whenever crontab files were updated.

  • Trying to create a shell script to cut/paste files in finder. Help needed.

    I'm trying to create an automator shell script to cut/paste. It'll function exactly like copy/paste. i.e. I'll just copy file/files with command+c like always, but then I'll create an automator which uses the "mv" terminal app to move the files which works exactly like cut paste.
    I need some help since I don't know the syntax for creating shell scripts.
    What I did so far is to do it in automator with Apple Script which goes like the following:
    on run {input, parameters}
    tell application "Finder"
    set theWindow to window 1
    set thePath to quoted form of (POSIX path of (target of theWindow as string))
    end tell
    tell application "Terminal"
    do script with command "mv \"" & input & "\"" & thePath in window 1
    end tell
    return input
    end run
    This gets the copied file path from clipboard before, as input, and then recognizes the active finder window as thePath so then executes the mv command for the input file to the thePath window.
    It doesn't work as expected since it connects both file/window paths into a single path instead of leaving a space between them so the mv command can't recognize two separate paths.
    What's the correct syntax for that line
    do script with command "mv \"" & input & "\"" & thePath in window 1
    to leave a space between input and thePath under the mv command?
    Also this requires the terminal app to be open in the background.
    After I get this to work I want to do the exact same thing using shell script within automator, so I won't need Terminal to be open all the time.
    And the next step will be to cut/paste multiple files/folders but that should be easy to do once I get the hang of it.

    Try using:
    on run {input, parameters}
    tell application "Finder"
    set theWindow to window 1
    set thePath to quoted form of (POSIX path of (target of theWindow as string))
    end tell
    do shell script "mv \"" & input & "\" " & thePath
    return input
    end run
    (45977)

  • Shell script that required password

    Hi,
    I'm using an automator script to upload some files to a remote Linux server, and I'm using rsync in an automator shell script action.
    That command required a password to work, how can I enter the password in the shell script action?
    Thanks

    Thanks for your answer, but as I'm no expert in AS,
    I'm not sure to understand your answer.
    How do those parameters are sent to AS?
    You put it in the statement:
    do shell script "rsync /source /dest" password "xyzzy" user name "you"
    You can set up a keychain for the password and retrieve it when needed, to be secure in your code. Post back or head over to AS forum, we'll help you out. http://discussions.apple.com/forum.jspa?forumID=724
    I suppose it can be run within Automator using a run
    AS instead of a run shell script. As my automator do
    some other task too.
    Yes, Automator has Run AppleScript action.
    And yes, you're right, iWeb publishing that is! Good
    guest!
    I saw some of your posts in iWeb board.
    I'm mucking around with iWeb, it's a bloated monster. There are quite a few restrictions in iWeb, I had to hand code some of the stuffs, such as meta data keywords, tricky stuffs... I'm thinking of writing a script for post production.

  • Run shell script Sudo or root?

    Any way I can run an Automator shell script with sudo or as root?
    I've been searching around and have found no information.
    Thanks in advance.
      Mac OS X (10.4.7)  

    Enter a command such as the following into an AppleScript action:
    on run {input, parameters}
    do shell script "ls -l /" with administrator privileges
    --do shell script "ls -l /" password "yourpass" with administrator privileges
    return input
    end run
    To have your password provided automatically to the script, uncomment the second do shell script line, delete the first line, and enter your password between the second pair of double quote marks. The command can be changed as needed; if the command is interactive, it likely won't work through this method.
    (13950)

  • Duplicate Text From Shell Script in Automator

    I'm trying to run a automator script that allows me to select a couple of files, run a sha1 checksum, and output a text file. My current version works 100% within the automator app, however when I use it as a context menu service, it outputs duplicate text. Here's my current workflow and what it outputs.
    Get Selected Folder Items
    Run Shell Script
    Copy to Clipboard (I've tried "new text file", and "new textedit file" as well)
    Outputs:
    SHA1(~/Desktop/Actions/Test/TEST.atn)= 88902acfb51e0f9a0c6dbedce69ce9618e26bc00
    SHA1(~/Desktop/Actions/Test/TEST.atn)= 88902acfb51e0f9a0c6dbedce69ce9618e26bc00
    Any help would be appreciated.

    Snow Leopard's Services workflow is automatically passed the type of selected items (that is what the selections at the top of workflow window are for), so just remove the *Get Selected Finder Items* action, since that is having the result of doubling the input items.

  • I am trying to use automator to make a simple app that when I open it, it comes up with a dialog box that asks for a link that you want to download. and it will download it for you using the curl -O shell script in Terminal. How would I do it?

    I want this so I can just download anything I want by just having the link and I have made a few things with shell scripts in automator before, just never anything where i need to input a value into the shell script.

    Easy:

Maybe you are looking for

  • Updation of sles group in sales order

    Dear all, The sales office and sales group is properly updated in the specific sales area master data of the customer but not flowing in the sales order and subsquently in the invoice. For some documents it gets updated and for others the filed is bl

  • OTEXBAS add on installation error: table ZAUTHCUST does not exist

    HI, i am installing an add on OTEXBAS. The installation terminated returning the error--- ZAUTHCUST does not exist. kindly suggest how to resolve this issue. the import log is below: ABAP Dictionary: Activation Transport request   : SAPK-301COINOTEXB

  • No pictures displayed

    This is for the computer at work. We're running a PowerMacG5, 160GB, dual 1.8G ghz. We opened ip iPhoto 4.0.3 (4H2) and all the photos are not being dislpayed. The photos are in the hard drive in their folders and albums as they had been before but i

  • How can I export hyperlinks from Numbers?

    I have a Numbers file with lots of hyperlinks used in it. I would like to export the data WITH the hyperlinks so that I can post it on my website. Exporting as CSV and copy-paste do not bring over the link references. Is there a way to do this?

  • ITunes not responding when I open it

    After not using iTunes for about a week, I opened it and was prompted to download the most recent version of iTunes. I did so, and followed the commands throughout the downloading process (or so I thought), but now when I click to open iTunes, it doe