{"id":16360,"date":"2016-11-12T14:51:26","date_gmt":"2016-11-12T19:51:26","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=16360"},"modified":"2016-11-12T14:51:26","modified_gmt":"2016-11-12T19:51:26","slug":"launchctl-asuser","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/11\/12\/launchctl-asuser\/","title":{"rendered":"launchctl asuser"},"content":{"rendered":"<p><a href=\"https:\/\/derflounder.wordpress.com\/2016\/03\/25\/running-processes-in-os-x-as-the-logged-in-user-from-outside-the-users-account\/\">Rich Trouton<\/a>:<\/p>\n<blockquote cite=\"https:\/\/derflounder.wordpress.com\/2016\/03\/25\/running-processes-in-os-x-as-the-logged-in-user-from-outside-the-users-account\/\">\n<p>One challenge that can crop up for Mac admins is the problem of running a script or other tool with root privileges and using it to launch and run another tool, script or application as if the logged-in user had launched it. An example of this would be installing Dropbox using an installer package, then launching the Dropbox application as the logged-in user as a post-installation task. One reason to do so would be to give the user the opportunity to sign into their Dropbox account.<\/p>\n<p>To accomplish this task, Apple has provided functionality in the <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Darwin\/Reference\/ManPages\/man1\/launchctl.1.html\">launchctl tool<\/a>.<\/p>\n<p>[&#8230;]<\/p>\n<p>Starting in <a href=\"https:\/\/en.wikipedia.org\/wiki\/OS_X_Yosemite\">OS X Yosemite<\/a>, Apple made a number of changes to the <strong>launchctl<\/strong> tool and added a new <strong>asuser<\/strong> function. The <strong>asuser<\/strong> function is designed to take the place of the <strong>bsexec<\/strong> function, <a href=\"https:\/\/lists.macosforge.org\/pipermail\/launchd-dev\/2015-July\/001139.html\">in the context of starting processes in the context of a specific user account<\/a>. This makes it easier, as you now just need to figure out the username and do not have to figure out the PID of the user&rsquo;s loginwindow process.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Rich Trouton: One challenge that can crop up for Mac admins is the problem of running a script or other tool with root privileges and using it to launch and run another tool, script or application as if the logged-in user had launched it. An example of this would be installing Dropbox using an installer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[30,1199],"class_list":["post-16360","post","type-post","status-publish","format-standard","hentry","category-technology","tag-mac","tag-mac-os-x-10-11"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=16360"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16360\/revisions"}],"predecessor-version":[{"id":16361,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16360\/revisions\/16361"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=16360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=16360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=16360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}