MacOS重新启动后如何运行Shell脚本

发布于 2025-02-04 22:58:55 字数 1193 浏览 3 评论 0原文

我已经在MacOS中写了一个Shell脚本来运行程序。通过命令行,我能够从任何地方运行脚本。

我已经写了.plist服务,并将其存储到/库/启动器/。我执行负载并启动功能。之后,当我重新启动系统但未执行脚本时。

在SH文件中,我要使用open filename.app打开.App文件。

另外,当我尝试在Automator中运行.App文件时,我尝试了另一种方式,例如使用Automator运行。它给我lsopenurlswithrole()失败了10810错误。

我将.plist文件存储在〜/library/lunageentent/and/library/lunageendaemons/中,但仍然没有结果。

我还将.plist文件放在系统偏好中 - >用户&组 - >登录项目。但是,在重新启动后,它打开shell脚本不执行它,它不会在其中运行命令。

以下是我的.plast文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN” “https://www.apple.com/DTDs/PropertyList-l.0.dtd“>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.start.activity</strings>
    <key>LaunchOnlyOnce</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>sh</strings
        <string>-c</string>
        <string>/usr/local/bin/rwm.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

,任何人,请帮助我。

I have written a shell script in macOS to run a program. through the command line, I'm able to run the script from anywhere.

I have written .plist service and stored it into /Library/LaunchAgents/. I perform load and start functionality. After that when I rebooted the system but script not executed.

In the sh file I'm opening .app file using open filename.app.

Also, I tried another way like running with Automator when I'm trying to run .app file in Automator it's giving me lsopenurlswithrole() failed 10810 error.

I store .plist file in ~/Library/LaunchAgents/ and /Library/LaunchDaemons/ but still got no result.

I also put .plist file in system preference -> User & group -> Login Items. But after reboot, it opens the shell script not execute it not run the command in that.

Below is my .plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN” “https://www.apple.com/DTDs/PropertyList-l.0.dtd“>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.start.activity</strings>
    <key>LaunchOnlyOnce</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>sh</strings
        <string>-c</string>
        <string>/usr/local/bin/rwm.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

Anyone, Please help me out from this.

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

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

发布评论

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

评论(1

花间憩 2025-02-11 22:58:55

您可能会在PLIST文件中缺少这些内容:

<key>AbandonProcessGroup</key>
<true/>
<key>KeepAlive</key>
<false/>

我有一个类似的脚本,需要将其正确运行。请注意,如果您需要此程序打开PTY/TTY和其他一些内容,则将被较新的MacOS安全功能所阻止。

如果您看到错误lsopenurlswithrole()失败10810,则启动服务在启动应用程序时遇到困难。

You may be missing these in the plist file:

<key>AbandonProcessGroup</key>
<true/>
<key>KeepAlive</key>
<false/>

I have a similar script and needed those to have it run properly. Note, if you need this program to open a pty/tty and some other things, they will be blocked by newer macOS security features.

If you see an error lsopenurlswithrole() failed 10810, Launch Services is having trouble launching the application.

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