Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Reply
8 replies

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.

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

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"

Trouble running automator shell script

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