打开终端并在Mac用户登录上运行命令

时间:2018-12-13 18:44:42

标签: macos automator launchd launch-agent

我正在尝试使启动脚本的一部分自动化,该脚本将打开一个终端窗口,该窗口将运行命令并在登录时向用户显示一堆文本。

我试图在/ Library / LaunchAgent中创建一个似乎无法解决问题的plist

/LaunchAgents/blah.blah.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "..........">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>terminal.menu</string>
    <key>RunAtLoad</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</script>
        <string>/Library/Scripts/Startup.sh</string>
    </array>
</dict>
</plist>

和Startup.sh看起来像这样

osascript -e 'tell app "Terminal"
    do script "echo blah blah ; ssh blah blah"
end tell'

1 个答案:

答案 0 :(得分:1)

根据来自here的信息,您可以对.plist进行一些修改:

  1. label的值应与您的.plist的名称(在这种情况下为"blah.blah")匹配,或者您应将.plist保存为"terminal.menu.plist"

  2. 您指定了ProgramArguments,但没有指定Program。也许如果您更改此设置:

    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</script>
        <string>/Library/Scripts/Startup.sh</string>
    </array>
    

    对此:

    <key>Program</key>
    <string>/Library/Scripts/Startup.sh</string>
    

所以您的blah.blah.plist定义现在看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "..........">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>blah.blah</string>
        <key>Program</key>
        <string>/Library/Scripts/Startup.sh</string>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>