There is no way to do this, "launchd" is the master process, the equivalent of "init" in other unix systems, the only way in any other daemon would be to perform some sort of kill -HUP to reload config files etc, but this operation is not permitted on launchd. If you look it up in the process table it is the number 1 process, every other process that is currently running is in some way a child of it, so a reboot is the only way to achieve this. You may have further luck in setting those environment variables in another area that is more inclined to allow restarts.
Dans-iMac:etc stuffe$ ps -ef | grep launchd | grep -v grep
0 1 0 0 9:40am ?? 0:09.47 /sbin/launchd
65 18 1 0 9:40am ?? 1:53.64 /usr/sbin/mDNSResponder -launchd
213 73 1 0 9:41am ?? 0:02.55 /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/Resources/usbmuxd -launchd
0 85 1 0 9:41am ?? 0:00.08 /System/Library/CoreServices/ODSAgent.app/Contents/MacOS/ODSAgent -launchd
89 230 1 0 9:41am ?? 0:00.01 /sbin/launchd
501 238 1 0 9:41am ?? 0:00.23 /sbin/launchd
501 933 238 0 10:53am ?? 0:00.01 /System/Library/CoreServices/AirPort Base Station Agent.app/Contents/MacOS/AirPort Base Station Agent -launchd -allowquit
EDIT:
Of course, missing the obvious solution that you can add the relevant variables into the config file, and then just run the commands manually in order to escape the need for a reboot, nothing that only newly start programs will take account of any changes. I found this page which explains it in more detail:
Environment variables set in launchd will be available to all programs on the system. However since $HOME/.launchd.conf is not
supported, this approach is used for global environment variables
only.
The /etc/launchd.conf file contains a list of commands to be run by
launchctl during startup. However environment variables set in
/etc/launchd.conf cannot have spaces and cannot reference other
environment variables; launchctl when run in Terminal does not suffer
these limitations. Do note that /etc/launchd.conf does not exist by
default, so we will need to create it.
A reboot is necessary to load the contents of /etc/launchd.conf.
However if you were to run the corresponding launchctlcommands in
Terminal, you can alleviate the need for the reboot. Just remember
that if you only do the launchctl commands, and do not put the entries
in /etc/launchd.conf, it will not persist after reboot.
If you want to have a system wide environment variable that uses
spaces or be dependent upon another environment variable, you can put
the launchctl commands into one of the files Terminal reads. You will
have to quit and relaunch Terminal to access the newly set variables.
Okay, I found a solution...
Chris Johnsen has a good writeup of what causes this problem on github.
His tools work, but a better solution, if you have homebrew installed to:
brew install reattach-to-user-namespace
Then in your ~/.tmux.conf
add these lines:
set-option -g default-command "reattach-to-user-namespace -l zsh" # or bash
bind C-c run "tmux show-buffer | reattach-to-user-namespace pbcopy"
bind C-v run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"
The first line ensures your shell can talk to pbpaste
, pbcopy
and launchctl
now with no worries.
The second line lets you copy the tmux
paste buffer into the Mac's paste buffer by typing control-b control-c (replace control-b with your tmux prefix key).
The third line will directly paste the Mac's paste buffer by typing control-v. As a side-effect it copies the Mac's paste buffer into tmux
's paste buffer.
I'd prefer if I could nuke tmux
's paste buffer entirely and have it paste directly into the Mac`s paste buffer, but... oh well.
Best Answer
No, there is no such functionality in
launchd
(as far as I am aware, and I consider myself pretty familiar withlaunchd
).The best site that I know of for
launchd
info is https://www.launchd.info which is maintained by the developer of LaunchControl which is my favorite, and I would argue also the best, tool for managinglaunchd
on the Mac, although I do have to admit that Lingon is also excellent.If I wanted to do something like that with
launchd
I would end up making a shell script of some kind to run the command before, then run the daemon, then run the commands after. Not nearly as satisfying, of course.