如何使用 Spotlight 运行 shell 脚本?

发布于 2024-09-02 17:14:43 字数 93 浏览 7 评论 0原文

有没有办法在 Mac OS X 10.6 上使用 Spotlight 运行 shell 脚本?我希望能够直接从 Spotlight 调用 shell 脚本,而无需打开终端。

Is there a way to run a shell script using Spotlight on Mac OS X 10.6? I would like to be able to invoke a shell script directly from Spotlight without opening up a terminal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恋竹姑娘 2024-09-09 17:14:43

使用 .command 后缀保存 shell 脚本 - 这使得它可以双击,并且您还应该能够直接从 Spotlight 运行它。

Save your shell script with a .command suffix - this makes it double-clickable and you should also be able to run it directly from Spotlight too.

软的没边 2024-09-09 17:14:43

另一种完全避免打开终端的方法:

在 Mac 上打开脚本编辑器,确保从语言下拉列表中选择 AppleScript,然后键入

do shell script "touch ~/testfile"

touch ~/testfile 替换为您选择的代码 - 如您所见它不需要有 .command 后缀,甚至实际上也不需要是脚本。

现在转到文件|导出并从文件格式:下拉列表中选择应用程序。确保所有选项:均未选中,并且从代码签名:下拉列表中选择不进行代码签名。随意命名,将其保存在任意位置。现在,您可以双击新的 AppleScript 应用程序或从 Spotlight 运行它,您的脚本将在不打开终端窗口的情况下运行。

作为一个额外的好处,因为它是 AppleScript,所以它可以与 Mac UI 交互——在显示对话框中显示结果、获取用户输入等。 https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_fundamentals.html

Another approach that completely avoids opening a Terminal:

Open Script Editor on your Mac, make sure AppleScript is selected from the language dropdown and type

do shell script "touch ~/testfile"

replacing touch ~/testfile with your code of choice--as you can see it need not have a .command suffix nor even actually be a script.

Now go to File | Export and select Application from the File Format: dropdown. Make sure all the Options: are unchecked and Don't Code Sign is selected from the Code Sign: dropdown. Name it whatever you like, save it wherever you like. Now you can double-click your new AppleScript application or run it from Spotlight and your script will run without a Terminal window opening.

As a bonus since it's AppleScript it can interact with the Mac UI--show results in a display dialog, get user input, etc. https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_fundamentals.html

隔岸观火 2024-09-09 17:14:43

我还想补充一点,如果您需要运行命令后终端窗口消失,您可以设置终端设置来做到这一点。

它位于设置>>>壳>>当外壳退出时。

这仍将使终端保持运行,但脚本至少会自行清理。

我用它来编写隐藏和显示桌面图标的脚本。

I would also like to add, if you need the terminal window to disappear after running the command, you can set the terminal settings to do just that.

It's under settings >> shell >> when the shell exits.

This will still leave Terminal running but the script will at least clean up after itself.

I used this for writing a script to hide and show desktop icons.

计㈡愣 2024-09-09 17:14:43

从 MacOS >= 10.0 开始,要使终端窗口在完成后消失:

Terminal > 首选项 >选择您的默认配置文件

然后 Shell > 当 shell 退出时 选择如果 shell 完全退出则关闭

To make the Terminal window disappear when finished as of MacOS >= 10.0:

Terminal > Preferences > Select your default profile

Then Shell > When the shell exits select Close if the shell exited cleanly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文