Disable Reopen Windows When Logging Back In (Mojave and Higher)

jan_rosenfeld
New Contributor III

Hello - last post on this topic I could find was from 2015.

Any way (Mojave and Higher) to disallow the "Reopen Windows When Logging Back In" across all Macs in a fleet?

I know the way this is controlled behind the scenes has changed over the years.

Thanks all! 7e1bc1b3ef874c39b587d7663b09a9f2

1 ACCEPTED SOLUTION

jan_rosenfeld
New Contributor III

@strayer I ended up running the following through Outset:

#!/bin/sh
user=`ls -la /dev/console | cut -d " " -f 4`
sudo -u $user defaults write com.apple.loginwindow TALLogoutSavesState -bool false

and all works perfectly!

View solution in original post

10 REPLIES 10

asiddiqui
New Contributor II

I would be interested to know this as well.

JustDeWon
Contributor III

I believe this should do the trick

defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

Also, I haven't tested the older commands in the newer OS, but a combo of these may still be accurate as well..

defaults write com.apple.loginwindow TALLogoutSavesState -bool false
defaults write com.apple.loginwindow LoginwindowLaunchesRelaunchApps -bool false

jan_rosenfeld
New Contributor III

defaults write com.apple.loginwindow TALLogoutSavesState -bool false was it - thank you!

jan_rosenfeld
New Contributor III

actually - weird- I ran it via my computer + terminal - works fine. I put it in execute command / files and processes via a policy - nothing. strange

AdamCraig
Contributor III

@jan.rosenfeld that's a user setting and Jamf commands run as root. You probably need to do something like this:

EDIT: Set this up in a jamf policy and it worked on my machine.

#!/bin/bash

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
loggedInUID=$(id -u "$loggedInUser")

#Disable Reopen Windows When Logging Back In
/bin/launchctl asuser "$loggedinUID" sudo -iu "$loggedInUser" defaults write com.apple.loginwindow TALLogoutSavesState -bool false

exit 0

Hi Adam

Did you run this policy at startup or login?

 

also how did you test it locally?(not through jamf)

I run this policy once per computer during the initial setup. If the user wants to change it back I don't really care that much.
To test it locally put that text into a script file that ends in .sh and then in terminal run

sudo sh /path/to/script.sh

It runs differently when running from Jamf though because scripts run as root and not as the logged in user. That's why you need the get logged in user and the sudo -iu $loggedInUser bit.

Hey, Adam. Been wanting to look at this for a while. I run this script and it runs successfully. But nothing changes. Do I need to plug the acct name of the logged in user as a variable? Thanks!

jan_rosenfeld
New Contributor III

@strayer I ended up running the following through Outset:

#!/bin/sh
user=`ls -la /dev/console | cut -d " " -f 4`
sudo -u $user defaults write com.apple.loginwindow TALLogoutSavesState -bool false

and all works perfectly!

Hi Jan

Can you explain how you used Outset?