在 OS X 中启动时运行脚本的最简单方法是什么?

Joh*_*hir 12 boot script login osx-snow-leopard macos

我想要一个脚本 (bash/zsh/ruby/...) 在启动时在 OS X 中运行。最简单的方法是什么,不要弄乱 xml/plist 文件,最好不需要制作元 AppleScript .

Ric*_*lka 7

MacOS X 使用 Vixie cron,它具有用于在重启时启动的特殊元标记。有关文件格式,请参阅手册页

就像是:

@reboot /path/to/script.sh
Run Code Online (Sandbox Code Playgroud)

在您的 crontab 中会起作用。我不确定这是否是比 launchd 更好的解决方案,您可能拥有比 cron 更多的元工具来查看 launchd。


Dan*_*eck 6

如果您改变意见:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.superuser.245713</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/script.sh</string>
    </array>
    <key>UserName</key>
    <string>someuser</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

存储为com.superuser.245713.plistin/Library/LaunchAgents/并创建root:wheel所有者/组。

  • @the0ther [网络不会忘记。](https://web.archive.org/web/20050728120657/http://www.afp548.com/article.php?story=20050620071558293) (2认同)