使可执行的 bash 文件在单击时运行
我有一个 bash 文件,可以进行一些文件操作。我不想每次运行时都必须打开终端。有没有办法让程序双击就运行? (就像 Windows .exe 文件)
谢谢
I have a bash file that does some file manipulation. I don't want to have to open the terminal every time I run it. Is there a way to make the program run when I double click it? (Like a windows .exe file)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 OS X 10.5+ 中,您可以包装 bash shell 脚本在使用
AppleScript
编辑器的AppleScript
应用程序 或使用Automator.app
的Automator
应用程序中(请参阅Automator
在线帮助)。您可以编写(并且有一些应用程序可以执行此操作)一个 OS X 应用程序,它接受任意
.sh
文件并执行它们。然而,这通常是一个坏主意,因为如果您无意中下载了由 Web 浏览器自动打开的恶意 shell 脚本文件,它可能会让您遭受攻击。最好明确一点。With OS X 10.5+, you can wrap the bash shell script in an
AppleScript
application using theAppleScript
editor or anAutomator
application usingAutomator.app
(see theAutomator
on-line help).You could write (and there are apps out there that do this) an OS X app that accepts arbitrary
.sh
files and executes them. However, that's generally a bad idea as it could open you up to attacks if you inadvertently download a malicious shell script file that is automatically opened by your web browser. Better to be explicit.您需要的是
Platypus
。What you need is
Platypus
.最简单的方法是输入:
sudo chmod 755 the_file_Name
。这将允许您双击查找器中的文件。The easiest thing to do is to type:
sudo chmod 755 the_file_Name
.This will allow you to double click on the file in the finder.您可以在文件名中添加“.command”扩展名 - 然后双击它将自动打开终端并在新窗口中运行脚本。注意:这假设您仍然想通过终端界面观看/与脚本交互;如果您也想避免这种情况,使用 Platypus、AppleScript 或 Automator(正如 Zifei 和 Ned 所建议的那样)包装脚本将是更好的选择。
You can add a ".command" extension to the filename -- then double-clicking it will automatically open Terminal and run the script in a new window. Note: this assumes you still want to watch/interact with the script via a Terminal interface; if you want to avoid this as well, wrapping the script with Platypus, AppleScript, or Automator (as Zifei and Ned suggest) would be better options.