4

Honestly, I'm finding Apple's launchctl and plist (XML?) usage to be somewhat confusing and overkill. Using Terminal, I just wanna say hey, macOS, start program.app at boot! or hey, macOS, start my /path/to/shell.sh at boot!

How can I add a boot item --remotely via Terminal/SSH/Netcat/command line/shell?

sh-3.2# system_profiler SPSoftwareDataType 
Software:

    System Software Overview:

      System Version: macOS 10.13.4 (17E199)
      Kernel Version: Darwin 17.5.0
      Boot Volume: lily
      Boot Mode: Normal
      Computer Name: lily’s MacBook Air
      User Name: System Administrator (root)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Enabled
      Time since boot: 2:03
  • There's more to it than just a startup program. Do you want it to launch for only one user, all users or regardless if a user logs in? See this primer on launchd. Here's another answer on how to run something at boot (no interval) – Allan May 18 '18 at 11:32
  • My frustration is exactly the same! Why does apple make it so hard to do such simple things? I hope someone could explain to me why this is necessary.. – Student May 4 at 14:50
3

LaunchDaemons – Run at Boot

LaunchAgents – Run at Login

So... you need a daemon

suggest you to cat /System/Library/LaunchDaemons/com.apple.pfctl.plist or any other in the same dir and use it as reference.

Just remove unnecessary. It will be something like this:

<?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>Disabled</key>
    <false/>
    <key>Label</key>
    <string>shell.sh</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/shell.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

save the file in the same dir, but named shell.sh.plist and run

sudo launchctl load /System/Library/LaunchDaemons/shell.sh.plist

to remove script from the load list:

sudo launchctl unload /System/Library/LaunchDaemons/shell.sh.plist

this is not linux so things are done Mac way.

man launchd & man launchd.plist will provide all needed info

OR

you can use an approach described here

Creating .plist just once and pointing it to your startup script which in turn will start anything you add there without need to write new .plist every time you want to start something new.

  • thanks. im making progress with this. the script requires internet access, how do i tell the plist to execute only after network connectivity has been established? – lily May 18 '18 at 15:12
  • This answer is incomplete and will result in failure(s) when the user attempts this. – Allan May 18 '18 at 15:12
  • @Allan how do you mean? – lily May 18 '18 at 15:12
  • @lily - I posted two links in the comments. The first one is a primer on launchd and creating the plists. See that. – Allan May 18 '18 at 15:13
  • @Allan is it possible to add a one-liner script into the plist so avoid sourcing a local file? – lily May 18 '18 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .