{"id":2840,"date":"2018-03-01T09:54:34","date_gmt":"2018-03-01T09:54:34","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=2840"},"modified":"2018-03-01T09:56:36","modified_gmt":"2018-03-01T09:56:36","slug":"launchctl-2-0-syntax","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=2840","title":{"rendered":"Launchctl 2.0 Syntax"},"content":{"rendered":"<h1 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 2.25em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.33333em; color: #242424;\">Loading and Unloading Daemon\/Agents<\/h1>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">In 10.9 and older, if you wanted to\u00a0load launchagent the command would look like:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl load \/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span>\r\n<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">And to unload it:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl unload \/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">An\u00a0assumption is made about how the launchagent is being loaded. For starters, it assumes the user loading\u00a0the agent\u00a0is\u00a0the\u00a0user\u00a0in the shell environment.\u00a0It might also make assumptions about whether the user is logged in a GUI.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">To better illustrate this, get on a computer which has 2+ users on it. Log into one account normally via the GUI. Open up Terminal, and switch the account (<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">su -l username<\/span><\/span>). If you have a computer which has multiple users and you switch the user in Terminal for one that is NOT logged in, you will get an error when running the above commands.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">So\u00a0what if you want to load the agent under a different user account? Previously you could rely on the following sub-commands:<\/p>\n<blockquote><p>bsexec PID command [args]<br \/>\nThis executes the given command in as similar an execution context as possible to the target PID. Adopted attributes include the Mach bootstrap namespace, exception server and security audit session. It does not modify the process\u2019 credentials (UID, GID, etc.) or adopt any environment variables from the target process. It affects only the Mach bootstrap context and directly-related attributes.<\/p>\n<p>asuser UID command [args]<br \/>\nThis executes the given command in as similar an execution context as possible to that of the target user\u2019s bootstrap. Adopted attributes include the Mach bootstrap namespace, exception server and security audit session. It does not modify the process\u2019 credentials (UID, GID, etc.) or adopt any user-specific environment variables. It affects only the Mach bootstrap context and directly- related attributes.<\/p><\/blockquote>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">But these sub-commands have been deprecated so they shouldn\u2019t be relied on.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">As you can see, it can get a little involved because you would need to gather certain information about the user or process. Rich Trouton\u00a0<a style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #e74f4e; text-decoration: none; transition: all 0.15s ease-in-out;\" href=\"https:\/\/derflounder.wordpress.com\/2016\/03\/25\/running-processes-in-os-x-as-the-logged-in-user-from-outside-the-users-account\/\" target=\"_blank\" rel=\"noopener\">documents this in an excellent blog post<\/a>.\u00a0Unfortunately, from what\u00a0I can tell, there is no replacement for\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">asuser<\/span><\/span>\u00a0or\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">bsexec<\/span><\/span>.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">In 10.10 or\u00a0greater, launchctl is much more explicit. In fact, Apple explains it as follows (can be found by typing\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">launchctl<\/span><\/span>\u00a0in Terminal in 10.11):<\/p>\n<blockquote><p>When using a legacy subcommand which manipulates a domain, the target domain is\u00a0inferred from the current execution context. When run as root (whether it is\u00a0via a root shell or sudo(1)), the target domain is assumed to be the\u00a0system-wide domain. When run from a normal user\u2019s shell, the target is assumed\u00a0to be the per-user domain for that current user.<\/p><\/blockquote>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">For 10.10 and 10.11, if you want to\u00a0load a\u00a0launchagent, the command would look like:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl bootstrap gui\/&lt;user's UID&gt; \/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">At least for 10.11, to unload it:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl bootout gui\/&lt;user's UID&gt; \/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Unfortunately, for 10.10 the sub-command\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">unbootstrap<\/span><\/span>\u00a0that is documented in the manual to unload the agent\u00a0does not work. You will get the output\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">Command is not yet implemented<\/span><\/span>.\u00a0Since it\u2019s an older operating system, you may want to rely on the deprecated command at least for that OS as they\u2019ve clearly changed the command name in 10.11. And don\u2019t worry, there are still other commands in 10.11 which also do not work as of yet and give you the same output.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Pay attention to the spacing after\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">gui\/&lt;user\u2019s UID&gt;<\/span><\/span>. To gather the user\u2019s UID, you can run the command:\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">id -u &lt;username&gt;<\/span><\/span>\u00a0where &lt;username&gt; would be the user account name you want to target.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The biggest change to point out is that you need to target a domain. The 3 most\u00a0applicable will be:<\/p>\n<blockquote><p>system\/[service-name]<br \/>\nTargets the system-wide domain or service within. Root privileges are required\u00a0to make modifications.<\/p>\n<p>user\/&lt;uid&gt;\/[service-name]<br \/>\nTargets the user domain or service within. A process running as the target user\u00a0may make modifications. Root may modify any user\u2019s domain. User domains do not\u00a0exist on iOS.<\/p>\n<p>gui\/&lt;uid&gt;\/[service-name]<br \/>\nTargets the GUI domain or service within. Each GUI domain is associated with a\u00a0user domain, and a process running as the owner of that user domain may make\u00a0modifications. Root may modify any GUI domain. GUI domains do not exist on iOS.<\/p><\/blockquote>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; text-decoration: underline;\">Note<\/span>: This information is available by typing\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">man launchctl<\/span><\/span>\u00a0in Terminal. Other domains do exist.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Some benefits to this change become apparent if you accidentally run something\u00a0under root or with\u00a0sudo. For example, this deprecated command would load the daemon as root.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl load \/Library\/LaunchDaemon\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchdaemon.plist<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">But the following deprecated command would also load the agent as root because its implicit due to sudo:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl load \/Library\/LaunchAgent\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchdaemon.plist<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Perhaps that\u2019s not what you meant to do. With the new syntax you can use sudo all you want (and in cases where you want to access another user environment other than the one you\u2019re in its required).<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Another thing to note is that you can unload everything in the user domain by not specifying a path:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl bootout gui\/&lt;user's UID&gt;<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">This leads to weird results so be careful using this.<\/p>\n<h1 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 2.25em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.33333em; color: #242424;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; text-decoration: underline;\">Listing running daemons\/agents<\/span><\/h1>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Under 10.9 or older, you would be able to list running\u00a0agents with the simple command:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl list<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">And if you wanted to get all the launch daemons\/launch agents running, you would simply do:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl list<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">This would give you a\u00a0Process ID (PID) of the daemon\/agent\u00a0along with the\u00a0exit code and the\u00a0job name. If you writing scripts, it can be rather handy to\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">grep<\/span><\/span>\u00a0against some of the results to compare against in conditional\u00a0statements.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">With 10.10 and newer, the\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">list<\/span><\/span>\u00a0sub-command is deprecated. The closest I can find is\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">print<\/span><\/span>which gives you a great deal more of detail. I\u2019ll give you a few\u00a0examples below.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl print gui\/&lt;user's UID&gt;<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">will print all the running services under that particular user domain.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl print\u00a0system<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">will print all the running services under root<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl print gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">will print detailed information about the specific launch agent. And if it\u2019s not running or you\u2019ve mistyped, you will get some output with a non-zero exit code:\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">Could not find service \u201c<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span>\u201d in domain for login<\/span><\/span><\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Unfortunately, Apple states:<\/p>\n<blockquote><p>IMPORTANT: This output is NOT API in any sense at all. Do NOT rely on the structure or information emitted for ANY reason. It may change from release to release without warning.<\/p><\/blockquote>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">So be sure to revisit every new OS to see if things change here.<\/p>\n<h1 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 2.25em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.33333em; color: #242424;\">Other sub-commands<\/h1>\n<h2 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 1.875em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.6em; color: #242424;\">enable\/disable<\/h2>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The sub-commands<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">\u00a0enable<\/span><\/span>\u00a0and\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">disable<\/span><\/span>\u00a0will enable\/disable a service.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The syntax looks as follows:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl disable gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">From what I gather, this may be more useful for a developer working with apps, but there is some interesting behavior to note here.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Let\u2019s say you\u2019ve loaded a launch agent\u00a0and then\u00a0disable it. You won\u2019t be able to load the launch agent thereafter until it has been re-enabled. For example, the following commands in succession:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl bootstrap gui\/&lt;user's UID&gt; \/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span><\/pre>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl disable gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl bootstrap gui\/&lt;user's UID&gt; \/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">That should give you an output of:<br style=\"box-sizing: border-box;\" \/><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">\/Library\/LaunchAgents\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.plist<\/span>: Service is disabled<\/span><\/span><\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">What\u2019s interesting here is that the launch agent is actually still loaded. Check it out yourself using the new\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">launchctl\u00a0print<\/span><\/span>\u00a0command (<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">launchctl print gui\/&lt;user\u2019s UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.company.launchagent.label<\/span><\/span><\/span>\u00a0). The state will show as\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">Running<\/span><\/span>. If you do disable the agent using<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">\u00a0launchctl bootout<\/span><\/span>\u00a0then you\u00a0cannot\u00a0load it again until you\u2019ve re-enabled the service.\u00a0Like I said, this may not be very useful to an admin, but something to be aware of nonetheless.<\/p>\n<h2 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 1.875em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.6em; color: #242424;\">uncache<\/h2>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The sub-command\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">uncache<\/span><\/span>\u00a0is\u00a0not yet implemented.<\/p>\n<h2 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 1.875em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.6em; color: #242424;\">kickstart<\/h2>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The sub-command\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">kickstart<\/span><\/span>\u00a0does have one interesting use. It does have a few options you can use with it, but the interesting one to know is how to restart\u00a0a service:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl kickstart -k gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">-k<\/span><\/span>\u00a0indicates you want to terminate the current service before it is restarted. If your launch agent uses\u00a0\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">KeepAlive<\/span><\/span>\u00a0then it will restart the agent and should be pretty apparent right away.\u00a0However, I want to caution\u00a0that this may not be the proper way to restart a launch agent and you should properly stick to unloading and loading using the commands shown earlier. My reasoning is that I\u2019m not a developer and launchd has been expanded to work with XPC services so its unclear to me if this is really meant for XPC services.<\/p>\n<h2 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 1.875em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.6em; color: #242424;\">kill<\/h2>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The sub-command\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">kill<\/span><\/span>\u00a0can be used as follows:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl kill &lt;signal name or number&gt; gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">This one is a little interesting because it utilizes signals that you can send to the launch agent. Might be handy for troubleshooting. Signal names and numbers can be found in\u00a0<a style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #e74f4e; text-decoration: none; transition: all 0.15s ease-in-out;\" href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Darwin\/Reference\/ManPages\/man3\/signal.3.html\">this Apple document<\/a>.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">For example, to terminate a process\u00a0simple do:<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl kill 9 gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">or<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl kill SIGKILL gui\/&lt;user's UID&gt;\/<span class=\"skimlinks-unlinked\" style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">com.comapny.launchagent.label<\/span><\/pre>\n<h2 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 1.875em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.6em; color: #242424;\">config<\/h2>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The sub-command\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">config<\/span><\/span>\u00a0can allow you to set the umask system wide or just across user domain. Apple\u00a0<a style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #e74f4e; text-decoration: none; transition: all 0.15s ease-in-out;\" href=\"https:\/\/support.apple.com\/en-us\/HT201684\" target=\"_blank\" rel=\"noopener\">documents it here<\/a>. It also lets you set PATH environment variables but I couldn\u2019t get it working (didn\u2019t try too hard on this one so I\u2019ll edit this blog post if the right syntax for it).<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl config system umask 000<\/pre>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl config user umask 000<\/pre>\n<h2 style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; font-size: 1.875em; margin: 0px auto 12px; outline: 0px; padding: 0px; vertical-align: baseline; clear: both; line-height: 1.6em; color: #242424;\">reboot<\/h2>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The last\u00a0sub-command that I\u2019ll over is\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">reboot<\/span><\/span>. This one is very interesting. You can essentially tell what you want to reboot. Be careful though or you will find yourself restarting the entire computer.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl reboot system<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">will reboot the entire system after it deconstructs the user domain.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl reboot userspace<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">will deconstruct the user domain. It will appear as if the computer is restarting, but really its just the user domain\u00a0that\u2019s being restarted.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl reboot halt<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">will deconstruct the user domain, but stop short of actually restarting the computer.<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl reboot logout<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">I\u2019ll let Apple explain the last two\u00a0because I think these can be pretty handy.<\/p>\n<blockquote><p>With the logout argument given, launchd will tear down the caller\u2019s GUI login session in a manner similar to a logout initiated from the Apple menu. The key difference\u00a0is that a logout initiated through this subcommand will be much faster since it will not give apps a chance to display modal dialogs to block logout indefinitely;\u00a0therefore there is data corruption risk to using this option. Only use it when you know you have no unsaved data in your running apps.<\/p><\/blockquote>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">launchctl reboot apps<\/pre>\n<blockquote><p>With the apps argument given, launchd will terminate all apps running in the caller\u2019s GUI login session that did not come from a\u00a0launchd.plist(5) on-disk. Apps like\u00a0Finder, Dock and SystemUIServer will be unaffected. Apps are terminated in the same manner as the logout argument, and all the same caveats apply.<\/p><\/blockquote>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">Unfortunately, the last option does not completely work as of 10.11 and its noted by Apple in their manual. For example, if you have an app like Safari or System Preferences opened, it will quit it. But if you have an app like TextWrangler,\u00a0it remains opened.<\/p>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">And if you use the\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">-s<\/span><\/span>\u00a0flag\u00a0in either of these two scenarios it will reboot into single-user mode (because who needs a GUI, right?).<\/p>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl reboot -s system<\/pre>\n<pre style=\"box-sizing: border-box; border: 1px solid #d2cfcf; font-family: 'Droid Sans Mono', monospace; margin-top: 0px; margin-bottom: 24px; outline: 0px; padding: 24px 24px 24px 48px; vertical-align: baseline; background-color: #f1f0f0; position: relative; overflow: auto; max-width: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-wrap: normal; color: #242424;\">sudo launchctl reboot -s userspace<\/pre>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">The last option that I haven\u2019t covered, and frankly I\u2019m not sure in what scenario this would be handy, is the\u00a0<span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: italic; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><span style=\"box-sizing: border-box; border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">reroot<\/span><\/span>\u00a0option.<\/p>\n<blockquote><p>With the reroot argument given,\u00a0launchd\u00a0will perform a userspace shutdown as with the userspace argument, but it will exec a copy of\u00a0launchd\u00a0from the specified\u00a0mount-point.\u00a0 This mechanism is a light-weight way of changing boot partitions. As part of this process,\u00a0launchd\u00a0will make mount-point the new root partition and bring\u00a0userspace up as if the kernel had designated mount-point as the root partition.<\/p><\/blockquote>\n<p style=\"box-sizing: border-box; border: 0px; font-family: 'Noto Sans', sans-serif; margin: 0px 0px 24px; outline: 0px; padding: 0px; vertical-align: baseline; color: #242424;\">There are other sub-commands in launchctl, but they are beyond what I\u2019m interested in testing. Hopefully this post will help you with some of the syntax in\u00a0launchctl.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Loading and Unloading Daemon\/Agents In 10.9 and older, if you wanted to\u00a0load launchagent the command would look like: launchctl load \/Library\/LaunchAgents\/com.company.launchagent.plist And [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2840","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2840"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2840\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}