shoulihan

Q: 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!

MacBook, Mac OS X (10.7.3)

Posted on Apr 4, 2015 4:40 PM

Close

Q: Trouble running automator shell script

  • All replies
  • Helpful answers

  • by VikingOSX,

    VikingOSX VikingOSX Apr 4, 2015 6:22 PM in response to shoulihan
    Level 7 (20,591 points)
    Mac OS X
    Apr 4, 2015 6:22 PM in response to shoulihan

    In your Run Shell Script action, do you have Pass input: as arguments set? What is the rest of the workflow into this action?

     

    Normally, one sees an Application bundle as the following:

     

    /Users/aa/Applications/ffmpeg.app/Contents/MacOS/ffmpeg. Is what you have shown for the application path correct?

  • by shoulihan,

    shoulihan shoulihan Apr 5, 2015 3:18 PM in response to VikingOSX
    Level 1 (0 points)
    Apr 5, 2015 3:18 PM in response to VikingOSX

    I do have it set to arguments. Run shell script is the only item in the workflow (I'd like to add more, but I'm starting here since this isn't working). Like I mentioned, the BASH command runs fine if pasted into the terminal, so I don't think that's the issue. That's for the thoughts

     

    Screen Shot 2015-04-05 at 6.16.00 PM.png

  • by Tony T1,

    Tony T1 Tony T1 Apr 5, 2015 4:41 PM in response to shoulihan
    Level 6 (9,232 points)
    Mac OS X
    Apr 5, 2015 4:41 PM in response to shoulihan

    Debug with echo to see if the expansions are as expected:

     

    for f in "$@"
    do
      fn="${f%%.*}"
      echo /Users/aa/Applications/ffmpeg/ffmpeg -i "$f" -acodec libmp3lame -q:a 7 -ar 8000 -ac 1 "$fn.mp3" >> ~/Desktop/debug.txt
    done
    
  • by shoulihan,

    shoulihan shoulihan Apr 5, 2015 4:59 PM in response to Tony T1
    Level 1 (0 points)
    Apr 5, 2015 4:59 PM in response to Tony T1

    echo yields,

     

    "/Users/aa/Applications/ffmpeg/ffmpeg -i /Users/aa/Desktop/test.m4a -acodec libmp3lame -q:a 7 -ar 8000 -ac 1 /Users/aa/Desktop/test.mp3"

     

    which, if pasted into the terminal, processes the file no problem.

  • by Tony T1,

    Tony T1 Tony T1 Apr 5, 2015 5:08 PM in response to shoulihan
    Level 6 (9,232 points)
    Mac OS X
    Apr 5, 2015 5:08 PM in response to shoulihan

    That is very strange. 

    Is there anything in the [Results] tab in the Automator Action?

    What happens if you wrap it in an Automator Run Applescript Action with do shell script ?

  • by BobHarris,

    BobHarris BobHarris Apr 5, 2015 6:07 PM in response to shoulihan
    Level 6 (19,272 points)
    Mac OS X
    Apr 5, 2015 6:07 PM in response to shoulihan

    It is possible that your Terminal bash shell environment has additional environment variables that ffmpeg needs to find other resources, which are not present in Automator environment.

     

    Create an Automator "Run Shell Commnad" that does the following:

     

    ( pwd

    /bin/ls -dlaeO@ .

    id -a

    echo $#

    echo $0

    echo $*

    printenv ) >$HOME/tmp.out

     

    Run the automator app you create, then look at tmp.out in your home directory.

     

    Compare this output with what you get running these commands in an interactive Terminal bash shell environment.

  • by shoulihan,

    shoulihan shoulihan Apr 6, 2015 4:53 AM in response to BobHarris
    Level 1 (0 points)
    Apr 6, 2015 4:53 AM in response to BobHarris

    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

  • by shoulihan,Solvedanswer

    shoulihan shoulihan Apr 6, 2015 5:17 AM in response to shoulihan
    Level 1 (0 points)
    Apr 6, 2015 5:17 AM in response to shoulihan

    Thank you all a ton for the help. It was indeed something embarrassingly simple to fix. I just needed to have brackets around the fn variable. (I guess for some reason it's being parsed differently from automator than from the terminal? Maybe that's what you were point at, but I didn't see evidence for it in the outputs, but if I overlooked something I'd appreciate it if someone pointed it out to me.) It runs fine as:

     

     

    ~/Applications/ffmpeg/ffmpeg -i "$f" -acodec libmp3lame -q:a 7 -ar 8000 -ac 1 "${fn}.mp3"