How to avoid agent launching with 'Setup User'

Hi,


I have an assistant that launches using a LaunchAgent and a conditional file path.


The problem is during Setup Assistant sessions (after a macOS update for example) my app launches before the user logs in.

This is due to the Setup Assistant starting a session under Setup User.


Is there a smart/clean way to avoid the agent launching in this situation ?


Visibly launchd configuration files cannot help here. The only solution I see is checking the current user on app launch and abort if it's _mbsetupuser - and this solutions isn't clean at all. I'm not even sure it is possible under sandboxing.


Any Help ?


Regards,


Jerome

Accepted Reply

Thanks for that.

In your situation I’d change your launchd property list to point to a custom tool rather than

/usr/bin/open
, and then have that decide whether to launch Corp Assistant based on the current user.

Keep in mind that you’ll want this custom tool to not exit immediately once it’s launched Corp Assistant, but start its own monitoring of

~/Library/Preferences/.CorpAssistantDone
and stick around until that’s set. If it exits immediately then
launchd
is just going to relaunch it, which is not what you want.

Once you do that you can get rid of your override of

ThrottleInterval
, which is a bit weird.

Earlier you wrote:

The only solution I see is checking the current user on app launch and abort if it's

_mbsetupuser
- and this solutions isn't clean at all.

I’m not sure why you think that’s not a ‘clean’ solution.

I'm not even sure it is possible under sandboxing.

That should work just fine.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

Just to clarify because my wording is confusing.


My app is an assistant that opens using LaunchAgents after initial user login or other specific events.

It conflicts with MacOS Setup Assistant that launch after system updates.


I'd like my own assistant not to launch if MacOS Setup Assistant is ongoing.


Regards,


Jerome

What does your

launchd
property list file look like?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Quinn,


Here is my property file content (installed as LaunchAgent):


<key>Label</key>
<string>com.corp.assistant</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
<key>ProgramArguments</key>
<array>
  <string>/usr/bin/open</string>
  <string>-a</string>
  <string>/Applications/Utilities/Corp Assistant.app</string>
</array>
<key>KeepAlive</key>
<dict>
  <key>PathState</key>
  <dict>
    <key>~/Library/Preferences/.CorpAssistantDone</key>
    <false/>
  </dict>
</dict>
<key>ThrottleInterval</key>
<integer>604800</integer>

Thanks for that.

In your situation I’d change your launchd property list to point to a custom tool rather than

/usr/bin/open
, and then have that decide whether to launch Corp Assistant based on the current user.

Keep in mind that you’ll want this custom tool to not exit immediately once it’s launched Corp Assistant, but start its own monitoring of

~/Library/Preferences/.CorpAssistantDone
and stick around until that’s set. If it exits immediately then
launchd
is just going to relaunch it, which is not what you want.

Once you do that you can get rid of your override of

ThrottleInterval
, which is a bit weird.

Earlier you wrote:

The only solution I see is checking the current user on app launch and abort if it's

_mbsetupuser
- and this solutions isn't clean at all.

I’m not sure why you think that’s not a ‘clean’ solution.

I'm not even sure it is possible under sandboxing.

That should work just fine.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks. I'll try this.