如何通过双击在 OS X 中运行 shell 脚本? [英] How to run a shell script in OS X by double-clicking?

查看:21
本文介绍了如何通过双击在 OS X 中运行 shell 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 OS X 上具有用户执行权限的 shell 脚本,但是当我双击它时,它会在文本编辑器中打开.我怎样才能通过双击它来运行它?

I have a shell script that has user execution permission on OS X, but when I double click on it, it opens in a text editor. How can I get it to run by double-clicking it?

推荐答案

  • 首先在终端中输入以下命令使脚本可执行:

    • First in terminal make the script executable by typing the following command:

        chmod a+x yourscriptname
      

    • 然后,在 Finder 中,右键单击您的文件并选择打开方式".然后是其他……".

    • Then, in Finder, right-click your file and select "Open with" and then "Other...".

      在这里选择要执行文件的应用程序,在本例中为终端.为了能够选择终端,您需要从推荐应用程序"切换.到所有应用程序".(Terminal.app 应用程序可以在 Utilities 文件夹中找到)

      Here you select the application you want the file to execute into, in this case it would be Terminal. To be able to select terminal you need to switch from "Recommended Applications" to "All Applications". (The Terminal.app application can be found in the Utilities folder)

      请注意,除非您不想将所有文件与此扩展名关联以在终端中运行,否则您不应该使用始终打开方式"已检查.

      NOTE that unless you don't want to associate all files with this extension to be run in terminal you should not have "Always Open With" checked.

      单击确定"后,您应该只需双击即可执行脚本.

      After clicking OK you should be able to execute you script by simply double-clicking it.

      这篇关于如何通过双击在 OS X 中运行 shell 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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