-1
我知道您可以使用Automator从脚本创建应用程序,您可以从首选项应用到登录文件中......但是真的很想知道是否可以使shell脚本运行在启动只使用终端来设置?无需移动鼠标。顺便说一句。该脚本将启动我用于Web开发的不同服务:-)使用终端在启动时运行shell脚本? (Mac OS X)
谢谢!
我知道您可以使用Automator从脚本创建应用程序,您可以从首选项应用到登录文件中......但是真的很想知道是否可以使shell脚本运行在启动只使用终端来设置?无需移动鼠标。顺便说一句。该脚本将启动我用于Web开发的不同服务:-)使用终端在启动时运行shell脚本? (Mac OS X)
谢谢!
要运行脚本/命令,您可以使用launchd
。
你需要专门有2个文件。
1)你的shell脚本。
2)plist文件。
以下是样本plist:另存为com.example.exampld.plist
。标签和plist的名字是首选苹果给予相同。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.exampled</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>absolute_path_to_script</string>
</array>
</dict>
</plist>
并将其放置在根据您的需要。
以下是文件夹:
|------------------|-----------------------------------|---------------------------------------------------|
| User Agents | ~/Library/LaunchAgents | Currently logged in user
|------------------|-----------------------------------|---------------------------------------------------|
| Global Agents | /Library/LaunchAgents | Currently logged in user
|------------------|-----------------------------------|---------------------------------------------------|
| Global Daemons | /Library/LaunchDaemons | root or the user specified with the key UserName
|------------------|-----------------------------------|---------------------------------------------------|
| System Agents | /System/Library/LaunchAgents | Currently logged in user
|------------------|-----------------------------------|---------------------------------------------------|
| System Daemons | /System/Library/LaunchDaemons | root or the user specified with the key UserName
|------------------|-----------------------------------|---------------------------------------------------|
根据您的需要将其无论是在第一或从上面列表中第二个文件夹。
要运行脚本,请使用launchctl
加载它或重新启动mac。
加载和卸载脚本:
退房apple website为可在plist中使用的密钥。
我希望它有帮助。
keepAlive是什么?这个键对shell脚本没用。 – vadian
@vadian为什么?任何原因? – SkrewEverything
Shell脚本没有runloop。 'keepAlive'只对有runloop的进程在必要时重新启动进程很有用。此外,'LaunchOnlyOnce'和'keepAlive'是矛盾的。 – vadian