MacNN Forums (
-   macOS (
-   -   Application running in wrong user screen when started using launchagent (

vipinjohney Jun 12, 2013 07:44 AM
Application running in wrong user screen when started using launchagent
I have a LaunchAgent with starts my app when loaded. This app will run on per user mode. When there are multiple users logged in using fast user switch, the app should run for each user.

So the binary loading the LaunchAgent is running as root. For loading I am giving the command as

launchctl bsexec 64 chroot -u <username> / launchctl load -w -F -s Aqua /Library/LaunchAgents/<name_launchagent>.plist
The number 64 is the PID of loginwindow.
This command is executed for each user logged in with PID of loginwindow for each user.
But all this app are appearing on the window of the currently logged in user. The app is a menubar app, when launchagent is loaded for each user, current active user's menubar fills with multiple icons of app loaded for each user. In activity monitor I could see that the user name for each app is correctly specified.

Can some help me on this. Why is the app for other users shown on the currently logged in screen?!.
Is there any other way to load app for all the users currently logged in to the system?

Vipin Johney
P Jun 12, 2013 09:26 AM
Not an expert of launchctl, but...why are you using chroot? That command will only change the perceived root directory of a process. Is that what you're trying to do?
vipinjohney Jun 14, 2013 12:57 AM
Yes that's what I was trying .
The binary from which the command is executed is running under root and I want to load the LaunchAgent as users logged in to the machine, that's why I am using chroot command.
P Jun 14, 2013 04:47 AM
That's not what chroot does. chroot changes the root directory as seen by the program, not the user that runs a program - basically, it make the program unable to move "up" in the directory tree. Root can switch to any other user with the command "su" and execute a single command as another user with "sudo". Check out those commands.

Again, barely ever used launchctl, but generally you can't just chain commands like that by typing them after each other. If you want one command to wait for the previous to execute first, chain them with &&.
All times are GMT -4. The time now is 02:25 PM.

Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.

Content Relevant URLs by vBSEO 3.3.2