Automtor shell script "command not found"

I want to include the execution of a shell script in Automator. The script just executes a third-party application (actually, pdftk) with certain parameters. I have written the script, saved it in my Home directory as "foo.sh", made it executable, and can correctly call it from Terminal with ./foo.sh. It works as expected.


But if I include it in Automator's workflow, into action "Run shell script", its execution breaks complaining that "pdftk: command not found". This indicates that the script is correctly found and read by Automator. How is it, that Terminal's bash can find the command, but Automator doesn't ? Have commands to be written in a special way to be understood by Automator ? Perhaps third-party commands are not allowed in Automator ?

Posted on Oct 4, 2013 11:20 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 4, 2013 11:36 AM

in automator (and applescript) shell scripts you can not rely on the same settings you expect in terminal. In particular, the $PATHS variable may be different and the working directory may not be what you expect it to be. Make sure you've spelled out the full path for utilities or scripts you call from your script.

3 replies
Question marked as Top-ranking reply

Oct 4, 2013 11:36 AM in response to catalan

in automator (and applescript) shell scripts you can not rely on the same settings you expect in terminal. In particular, the $PATHS variable may be different and the working directory may not be what you expect it to be. Make sure you've spelled out the full path for utilities or scripts you call from your script.

Oct 4, 2013 11:52 AM in response to catalan

As twtwtw has said, you environment when running Automator is NOT the same as when you are in a Terminal session.


    
pwd:
/Users/harris


    
/bin/ls -dlaeO@ .
    
drwxr-xr-x  349 harris  harris  - 11866 Mar 14 22:06 .


    
id -a:  uid=501(harris)
            
gid=501(harris)
            
groups=501(harris),
                   
204(_developer),
                   
100(_lpoperator),
                    
98(_lpadmin),
                    
80(admin),
                    
61(localaccounts),
                    
12(everyone)


    
$# 0


    
printenv: SHELL=/bin/bash
              
TMPDIR=/var/folders/zv/zvU6+bMiHTeElG+JIWOdzk+++TI/-Tmp-/
              
Apple_PubSub_Socket_Render=/tmp/launch-rVMvHQ/Render
              
USER=harris
              
COMMAND_MODE=unix2003
              
SSH_AUTH_SOCK=/tmp/launch-fH4Gt7/Listeners
              
__CF_USER_TEXT_ENCODING=0x1F5:0:0
              
PATH=/usr/bin:/bin:/usr/sbin:/sbin
              
PWD=/Users/harris
              
DBUS_LAUNCHD_SESSION_BUS_SOCKET=/tmp/launch-RIPIu6/unix_domain_listener
              
SHLVL=1
              
HOME=/Users/harris
              
LOGNAME=harris
              
DISPLAY=/tmp/launch-ttdbVO/org.x:0
              
FRED=3-Mar-2009
              
_=/usr/bin/printenv

Oct 4, 2013 12:02 PM in response to twtwtw

Thanks! I had already read this warning, but thought it mainly concerned paths to my files and the like. This time, I realized that what I had to write differently was the path to the pdftk command! I found it nested inside several directories, in the /opt directory. Then I wrote its complete path in the shell script file, and voilà! It works as expected!

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.

Automtor shell script "command not found"

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