Search code examples
macosautomatorlaunchdlaunch-agent

Open terminal and run commands on Mac User Login


I am trying to automate a part of start up script that would open a terminal window that would run commands and display a bunch of text to user upon login.

I tried to create a plist in /Library/LaunchAgent that doesn't seem to do the trick

/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>

and the Startup.sh looks like this

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

Solution

  • Based on information from here, there are a couple of edits you could make to your .plist:

    1. The label value should match the name of your .plist, in this case "blah.blah", or you should save your .plist as "terminal.menu.plist".

    2. You've specified ProgramArguments, but no Program. Perhaps if you change this:

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

      to this:

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

    So your blah.blah.plist definition would now look like this:

    <?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>