Close Mail window on "sign in"

I want to be able to close the Mail window/s if open when I sign in. I placed this script into login items and it does not fire when I sign in and the Mail window is open, yet it does fire when I click on it in the login window.


So, if the mac is asleep and the mail window is open and I sign in, the script does not fire. Does it need additional language, since I am signing in to a mac that is just asleep and is asking for a password since the energy saver sleep setting is beyond the 3 minutes it is set to? Running Catalina

Thanks


tell application "Mail"

try

close every window

end try

end tell



iMac Line (2012 and Later)

Posted on Jan 5, 2020 3:38 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 6, 2020 11:44 AM

There seems to be some misunderstanding as to how the login items work.


Login items run when you first log into your account (after a shut down/restart, or after you explicitly log out).


By definition at this time, Mail won't be running, so there's nothing to do (chances are, even if you have Mail set to open at launch the script would fire before Mail had a chance to do anything).


As for waking from sleep, the is nothing that invokes Login Items on wake - you're already logged in, so there's nothing to do.


AFAIK, there is no trivial way to execute a script on wake. There are some third-party apps that have this ability, though.


SleepWatcher

Scenario

Power Manager


4 replies
Question marked as Top-ranking reply

Jan 6, 2020 11:44 AM in response to mrokloricred37

There seems to be some misunderstanding as to how the login items work.


Login items run when you first log into your account (after a shut down/restart, or after you explicitly log out).


By definition at this time, Mail won't be running, so there's nothing to do (chances are, even if you have Mail set to open at launch the script would fire before Mail had a chance to do anything).


As for waking from sleep, the is nothing that invokes Login Items on wake - you're already logged in, so there's nothing to do.


AFAIK, there is no trivial way to execute a script on wake. There are some third-party apps that have this ability, though.


SleepWatcher

Scenario

Power Manager


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Close Mail window on "sign in"

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.