Apple Remote Desktop Restart Functionality w/ Reopen Windows False

iamYaje
New Contributor III

Hi all,

We use Apple Remote Desktop (ARD) to send restart commands to a fleet of Macs in our classrooms. These computers are set to auto-login to a user account (these are computers behind locked doors and monitored). That user account is configured to not have windows reopen upon restart. 

com.apple.loginwindow

 

<TALLogoutSaveState</key>
<false/>

 

 

That works great on a restart initiated manually from one of the client computers. No open windows reopen upon restart and auto login. Unfortunately, it does not seem to work when initiating a restart from ARD. I haven't determined why this is.

At first I thought maybe it's because it's sending as the root user and that might be changing/ignoring something. So I tried sending the restart with a Unix Command from an admin account:

 

 

echo "localAdminPass" | sudo -S shutdown -r now

 

 

 Well, that command worked fine, but the windows still reopened.

Does anyone have any idea of why this is? Any work arounds to getting the configuration profile to keep windows closed when submitted ARD restarts?

Thanks!

6 REPLIES 6

AJPinto
Honored Contributor II

Commenting to keep an eye on this. MacOS's default behavior or reopening all your apps annoys the mess out of me. If there is a way to kill that function I am all for it.

sdagley
Esteemed Contributor II

@iamYaje If you initiate the restart via the GUI (as in have the person connected via ARD select Restart from the Apple menu) do you see the same behavior? My guess is that the ARD initiated restart, and the scripted shutdown command, are being considered an abnormal shutdown and macOS is trying to be "helpful" by re-opening windows in this case.

iamYaje
New Contributor III

@sdagley @AJPinto I'm coming back to these forums and want to correct what I previously said here. I did not read your post correctly and misunderstood what you were saying to do with the GUI. I intuited that you meant using the GUI of ARD to select a restart command. I must have been confused at the time. I see now that you meant to use the control feature of ARD to gain control over the desktop of the target computer and to navigate a restart from the Apple menu. It's obvious when reading it now!

The correct answer is that when doing a user-initiated, "soft" restart (as I'm calling it now), the restart will go through without reopening windows. When I realized this, I ended up creating a custom restart script that uses Apple script to navigate a restart on the target computers. It focuses on the apple menu, navigates down with down arrow key presses to the restart, and returns twice. But first, applications need to close, and some need to be forcefully closed so that they do not prevent the user form restarting. So I scripted a loop through applications to either close or forcefully close. This pretty unique to our environment since we will have a single user on the computer only for an hour at a time, and then move on to the next, and they are all in a controlled environment.

Here's the script if you're curious:

#!/bin/bash

# Define list of applications to force quit
apps1=(
	"Zoom" 
	"DiLL" 
	"Microsoft Powerpoint" 
	"Microsoft Word" 
	"Microsoft Excel" 
	"System Settings" 
	"Remote Desktop"
	"GarageBand"
	"Terminal"
	"Activity Monitor"
	"Finder"
	"Pages"
	"Music"
	"Photo Booth"
	"Numbers"
	"Praat"
	"Weather"
	"Freeform"
	"Maps"
	"Messages"
	"Calendar"
	"Mail"
)

# Loop through each application and force quit if it's currently running
for forceQuit in "${apps1[@]}"; do
    if pgrep -i "$forceQuit" >/dev/null; then
        echo "Force quitting $forceQuit"
        pkill -9 -i "$forceQuit"
    fi
done

# Define list of applications to quit with AppleScript
apps2=(
	"Google Chrome"
	"Firefox"
	"Safari"
	"App Store"
	"Terminal"
	"Stocks"
	"News"
	"Home"
	"Keynote"
	"Quicktime Player"
	"Chess"
)

# Loop through each application and quit if it's currently running
# Use AppleScript to gently quit browsers and prevent the restore user session prompt
for osaQuit in "${apps2[@]}"; do
    if pgrep -i "$osaQuit" >/dev/null; then
        echo "Quitting $osaQuit"
        osascript -e "tell application \"$osaQuit\" to quit"
    fi
done

# Perform gentle restart using osascript commands
osascript <<'EOF'
tell application "System Events"
	key code 120 using {control down} -- focus to apple menu control+F2 code 120
	delay 1.5
	repeat 8 times -- loop keypress of down arrow code 125
		key code 125
		delay 0.5
	end repeat
	keystroke return -- return on restart...
	delay 1
	keystroke return -- return again
end tell
EOF

This gets sent to all target computers at once and basically replaces the ARD native command that sends a forced restart to the computers. No browsers reopen and offer to reopen their saved state, and the restart itself is as though initiated by the user.

iamYaje
New Contributor III

@sdagley Yes, whether I send the restart via a Unix command or via the GUI of ARD, the result is the same and the windows reopen, despite the config.

Yours is a good thought. If there is any way to stop the helpfulness, I would be very happy :-P

 

Do any ideas come to mind? I have no idea how to start looking for that. I can't imagine how to capture it in a snapshot, for example...

iamYaje
New Contributor III

Well, I haven't done much to pursue a solution to whatever is the root cause of the .plist configuration not taking affect.

However, I have a work around that might work. Use ARD to send a unix command to each of the computers, —sent as root — to call upon a custom trigger for a Jamf policy with a restart payload. Ensure it's scoped to each of the computers and delivered on an ongoing basis. I'll test it soon.

If that works, I'll be curious to know what the difference between the command 

shutdown -r now

and the Jamf Pro restart payloads.

Additionally, since I'm are attempting to force a restart, I'm not sure how the Jamf restart payload will behave with popups that prevent shutdown.

 

iamYaje
New Contributor III

@AJPinto @sdagley 

Whether I use

shutdown

or

reboot

or osascript:

osascript -e 'tell app "System Events" to restart'

It's treated as an abnormal shutdown. I was surprised because osascript's command almost appears to close windows like a normal shutdown, but it does not.

I thought I might be going crazy and forgot to scope the config profile to disable reopen windows, but it's scoped correctly and it works perfectly on a normal restart initiated from the computer.

I've tried using a delayed restart instead of immediate, and the result is the same.

I've tried to write to NSGlobalDomain with a policy:

defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

I've tired to write to the Bundle_ID of an app directly with a policy:

defaults write com.google.Chrome NSQuitAlwaysKeepsWindows -bool false

Finally, I have a workaround that I'd rather not use if I don't have to: upon startup/login deliver a kill command to the common apps that would be open (via policy Files & Processes line or a script):

kill -9 $(pgrep "Google Chrome")

 

My next thought is to use ARD to send an osascript that just uses keystrokes to enter the apple menu, navigate down to restart, and enters through the prompts. Or to initiate a logout first and then navitage to a restart.

That's the only way I can think of to send a command to initiate a "normal" restart... it's boggling my mind that there isn't a command that initiates a normal restart from a user. Although, I have read some old forums where scripts have been shared that use the logged in user to commit the restart... maybe that's what's necessary?