How to run a command on Macbook startup?

1

I'm running the latest Sierra version, and every time I reboot I need to execute

mysql.server start

I'd like to simply add this command to a startup script, but I've spent an hour looking at setting up daemons, etc, but I feel like it shouldn't be that difficult.

Is there an easy way to put this in some sort of startup script so every time I start my macbook it's run in the background?

Any help would be appreciated!

Mark Kadlec

Posted 2017-02-21T23:25:55.567

Reputation: 113

Answers

5

If you want it to happen when you log in, put it in your user account's Login Items (System Preferences > Users & Groups > [Your Account] > Login Items).

If you want it to happen on every boot, regardless of whether or not anyone logs in (and regardless of who logs in), then create a launchd plist file for it and put said plist in /Library/LaunchDaemons/. See the man page for launchd.plist(5), or other online tutorials and tools for creating launchd jobs.

Spiff

Posted 2017-02-21T23:25:55.567

Reputation: 84 656

thanks for the response, the Login Items sounds like an easy thing, I added a .sh script but it doesn't seem to run when I login, any ideas? – Mark Kadlec – 2017-02-27T18:32:42.457

1@MarkKadlec A few ideas: Make sure you've chmoded the script to be executable. Try renaming the myscript.sh to myscript.command. Make sure it opens up Terminal and runs when you double-click it from the Finder. – Spiff – 2017-02-27T22:16:38.880

Changing to .command seems to have fixed this! – Mark Kadlec – 2017-03-02T20:31:50.017