In fact, the principle is very simple, using LAUNCHD to create a start-up service, and then the service associated/etc/rc.local file, then the next operation Rc.local and Linux under the same.
Of course, this idea can also be used directly on the ~/.BASHRC file, but this way has a disadvantage, that is, permissions are not root, so the scope of application is much smaller. The user who executes the script inside the file created by this service is root and has the highest permissions.
Description: About LAUNCHD users directly on the Apple developer site query, clues can be this launchctl
Implementation steps:
Go to /Library/LaunchDaemons
Catalog
Cd/library/launchdaemons
Create a plist file
sudo vim local.localhost.startup.plist
Copy the following to the file save. (Press "ESC", then ": wq!", enter)
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE plist Public "-//apple computer//dtd plist 1.0//en" "Http://www.apple.com/DTDs/PropertyList-1.0.dtd "><plistversion= "1.0"> <Dict> <Key>Label</Key> <string>Local.localhost.startup</string> <Key>Disabled</Key> <false/> <Key>Runatload</Key> <true/> <Key>KeepAlive</Key> <false/> <Key>Launchonlyonce</Key> <true/> <Key>Programarguments</Key> <Array> <string>/etc/rc.local</string> </Array> </Dict></plist>
Adding as a service using LAUNCHCTL
sudo launchctl load-w ./local.localhost.startup.plist
Finally, create the rc.local file,
sudo vim/etc/rc.local
Write the commands that need to be executed on the inside. Remember to give the rc.local
file x
permission (executable)
sudo chmod +x/etc/rc.local
Reference:
http://blog.csdn.net/maxsky/article/details/55061453 (the above content is transferred from this article, the deletion of the dialogue)
http://blog.csdn.net/abby_sheen/article/details/7817198
Use LAUNCHD to implement power-on Start command with Rc.local under Mac