Run Shellscript from Mac Automator

On OS X 10.9.5

I wrote a Script shell (via vim). Save it and go to this Script and

sh code.sh It works great (in iTerm and Total Terminal).

The same command in the same directory always creates ERROR through Mac Automator. Why?

in Automator and in the terminal.

echo $SHELL /bin/bash Why is it impossible to run shellscript through Automator. enter image description here

+4
source share
3 answers

I suspect this is a bit cd Desktop. You can try:

(cd ~/Desktop; sh code.sh)

However:

  • You must make an executable code.sh, so you do not need to call it with sh. This is done using chmod 0755 code.sh.

  • script ( , script), script, ~/Desktop/code.sh

    #!/bin/bash
    dir=$(dirname $0)
    cd $dir
    # do work
    

:

➜  ~  cat tmp/code.sh
#!/bin/bash
dir=$(dirname $0)
cd $dir
ls -l

➜  ~  chmod 0755 tmp/code.sh
➜  ~  tmp/code.sh
total 64
drwxr-xr-x   6 andy  staff    204 Feb 22 18:53 Archives
drwxr-xr-x  11 andy  staff    374 Jun 18 13:59 DerivedData
-rw-r--r--   1 andy  staff    225 May 20 13:44 MyFirstProgram.X
-rwxr-xr-x   1 andy  staff   3072 May 20 13:44 MyFirstProgram.exe
drwxr-xr-x   3 andy  staff    102 Jan  6  2014 bug_reports
-rwxr-xr-x   1 andy  staff     43 Aug  6 14:15 code.sh
-rw-r--r--   1 andy  staff  11539 May 20 08:33 iOS_Team_Provisioning_Profile_.mobileprovision
-rw-r--r--   1 andy  staff   1438 May 20 08:40 ios_development.cer
-rwxr-xr-x   1 andy  staff    272 Aug  5 08:55 script.sh
+3

: Automator: env > ~/Desktop/file_1.txt iTerm: env > ~/Desktop/file_2.txt

DIFF

diff -y ~/Desktop/file_1.txt ~/Desktop/file_2.txt

, , ! , . export LANG=de_DE.UTF-8 script, !

+2

This problem can be solved by adding the following code above your current code:

export PATH=/usr/local/bin:$PATH
+2
source

All Articles