brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: launchctl kickstart -k restarts a background agent on your Mac

Terminal
~/tips/tip-macos-launchctl-kickstart-restart

launchctl kickstart -kp gui/$(id -u)/com.example.agent

Restarts a stuck background job through launchd instead of killing it blindly.

When a menu bar helper or a sync agent hangs, quitting it in Activity Monitor feels like a guess: will it come back on its own or not? If the thing runs as a launchd agent, launchctl can restart it properly.

The subcommand is kickstart. With -k it kills the running instance first and then starts the service again; -p prints the PID of the new process. The target is written as a domain plus the job’s label. For agents in your own login session that domain is gui/ followed by your user ID:

launchctl kickstart -kp gui/$(id -u)/com.example.agent

Swap com.example.agent for the label of the job. You’ll find it as the file name of the plist in ~/Library/LaunchAgents (minus .plist), or in the Label column of launchctl list. Without -k, kickstart only starts a job that is not running and leaves a running one alone, which I’d use when I’m not sure.

Daemons that run for the whole machine sit in the system/ domain instead. Anyone may read that domain, but changes need root, so those take sudo:

sudo launchctl kickstart -k system/com.example.daemon

The caveat: a kickstart restarts the process, it does not read an edited plist again. If you changed the plist itself, use launchctl bootout and launchctl bootstrap, which the man page describes as the new forms of unload and load. And I’d keep this to my own agents and third-party ones. Killing Apple’s own services just to see what happens is a good way to spend an afternoon rebooting.

Further reading: launchctl man page (ss64)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link