1

I have multiple users on a single iMac. They stay logged on, but put the display to sleep via a hot corner when finished. After a short time, a password is required and this allows them to switch users when necessary.

I have some code that runs via a script, accessing the user's library (mail). It is set to run nightly (different time) for each user via a launch agent in their ~/Library/LaunchAgents folder.

The problem is that the launch agent for the 'non-active' user does not trigger. It does trigger for the 'active' user, even though the display (not the computer) is sleeping.

I understand that an agent will not run for a user who has logged off.

Is there some way to get both agents to trigger?

3
  • One way to do this is if you're talking about the mail command or other cli tools is to use cron instead of launchd. If you're doing GUI things, like clicking around in Mail.app, it may be a problem of not having an active GUI session to interact with, in which case cron won't be helpful.
    – WarzauWynn
    Aug 4, 2022 at 19:03
  • The kicker would be the active GUI session. I use JXA (JS version of AppleScript) to archive emails. However, if the user is logged on, but inactive, I think moving the plist to Library/LaunchDaemons and adding the User and Group will work. Tested OK, but set up to run overnight, will update tomorrow. Aug 4, 2022 at 22:19
  • 1
    Turns out the test was not OK. Stupid Apple did not honor the try/catch, just aborted the app with no result at all. The script ended abruptly without any indication of an error. I debugged far enough to figure out that getting a reference to the Mail app, gets it for the current user, even if the script is being run as a different user, and I think permissions step in to stop it when it tries to access the mail folders. It should raise an error, but does not. Nothing in stdout or stderr either. Aug 5, 2022 at 17:57

1 Answer 1

0

It appears that this cannot be done if you are accessing an app like Mail through JXA or AppleScript. It may be possible if permissions are changed in places where they should not be, I did not go there.

The pertinent lines of code were:

var Mail = Application("Mail");
fromMboxRef = Automation.getDisplayString(Mail.inbox());

This did not work, did not raise an error, simply returned to the calling script. In JXA, it should raise an error, so what is the point of a try/catch if it is ignored?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .