从Mac的Automator运行shellscript里 [英] Run Shellscript from Mac Automator

查看:662
本文介绍了从Mac的Automator运行shellscript里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OS X 10.9.5

我写了一个shell脚本(通过VIM)。保存并导航到该脚本以及

SH code.sh 运行完美的(在的iTerm和放大器;总端子)。

在同一目录中相同的命令通过苹果的Automator产生总是一个错误。为什么呢?

在Automator中,并在终端。

回声$ SHELL
/斌/庆典

为什么无法通过的Automator运行shellscript里。


解决方案

我怀疑这是在 CD桌面位。你可以试试:

 (CD〜/桌面; SH code.sh)

不过:<​​/ P>


  • 您应该 code.sh 的可执行文件,所以你不需要用 SH 。这与搭配chmod 0755 code.sh 完成的。


  • 如果您需要在shell脚本从某个目录的工作(即该脚本所在的目录),然后建立一个到脚本,以便它可以只用调用〜/桌面/$c$c.sh

     #!/斌/庆典
    DIR = $(目录名$ 0)
    CD $ DIR
    # 做工作


例如:

 ➜〜猫TMP / code.sh
#!/斌/庆典
DIR = $(目录名$ 0)
CD $ DIR
ls -l命令➜〜CHMOD 0755 TMP / code.sh
➜〜TMP / code.sh
共有64个
drwxr-XR-X 6安迪人员204 2月22日18:53档案
drwxr-XR-X 11安迪人员374 6月18日13:59 DerivedData
-rw-R - R-- 1安迪人员225 5月20日13:44 MyFirstProgram.X
-rwxr-XR-X 1安迪人员3072 5月20日13:44 MyFirstProgram.exe
drwxr-XR-X 3安迪员工102 2014年1月6日bug_reports
-rwxr-XR-X 1安迪人员43 8月6日14:15 code.sh
-rw-R - R-- 1安迪人员11539 5月20日08:33 iOS_Team_Provisioning_Profile_.mobileprovision
-rw-R - R-- 1安迪人员1438 5月20日08:40 ios_development.cer
-rwxr-XR-X 1安迪人员272 8月5日08:55 script.sh

In OS X 10.9.5

I wrote a Shell Script (via vim). Save it and navigate to this script and

sh code.shit runs perfect (in iTerm & Total Terminal).

The same command in the same directory produces via Mac Automator always an ERROR. Why?

in Automator and in Terminal.

echo $SHELL /bin/bash Why is it impossible to run a shellscript via Automator.

解决方案

I suspect it's the cd Desktop bit. You can try:

(cd ~/Desktop; sh code.sh)

However:

  • You should make code.sh executable so you don't need to invoke it with sh. This is done with chmod 0755 code.sh.

  • If you need the shell script to work from a certain directory (i.e. the directory where the script is located) then build that into the script so it can be invoked with just ~/Desktop/code.sh:

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

For example:

➜  ~  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

这篇关于从Mac的Automator运行shellscript里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆