MacOS – running a simple shell script on startup in Yosemite

macbook promacosNetwork

Regarding stackexchange post how to get shell scripts to run at startup on Yosemite

The offering here is interesting but all I want to do is set the ip address of one of the ethernet interfaces, en0 with ifconfig. I don't want to launch a deamon.

the command to run is just:

ifconfig en0  inet netmask 

Of course the interface drivers have to be launched and the interfaces available for configuration.
This has to be run by root, other wise it has to be prefaced with sudo, which
has to have the credentials provided.

I have the root account activated on this system and am comfortable with and know most of the hazards.

But I don't want to do this manually every time the machine is booted or restarted.

Perhaps someone from Apple has a reference to a patch or info on why the
network preference operations for manual configuration of interfaces will not set them on mine.

I have been buying and using Macs since the late 1990's. This is one of only two out of nearly a dozen Macs I have owned that is not newly purchased from
a reputable dealer.

Apache server will also not launch with the web sharing option.

Perhaps the machine with the installation is too old? It is

 Model Name:    MacBook Pro
 Model Identifier:  MacBookPro5,1
 Processor Name:    Intel Core 2 Duo
 Processor Speed:   2.4 GHz
 Number of Processors:  1
 Total Number of Cores: 2
 L2 Cache:  3 MB
 Memory:    4 GB
 Bus Speed: 1.07 GHz
 Boot ROM Version:  MBP51.007E.B06
 SMC Version (system):  1.33f8
 <sn deleted for this post>
  Hardware UUID:    63410FEB-9CFF-5C8C-A692-8733BBEE36C5
 Sudden Motion Sensor:
 State: Enabled

This does not tell me its actuall manufacture date.

Thank you for time and attention


Best Answer

You could save your script whatever you want and call it from a .plist file saved on /Library/LaunchAgents/ to be launched at startup.

Let me explain how to do it with an example.

  • Create you script and save it on /Users/username/
  • Create a new file called com.username.setip.plist in /Library/LaunchAgents/. This file must have the following format:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">







The file is pretty self-explanatory. It will launch the command /Users/username/ every 60 seconds, will be launched at load, will save errors on /tmp/com.username.setip.err and logs on /tmp/com.username.setip.out.

Restart, and the script will be executed.