30

Sometimes my computer will crash and restart due to unknown errors. It usually happens when I'm working on something so a few apps are open. OS X has this annoying feature where it tries to reopen all apps when you restart. You can disable it when manually restarting, but it still does it if the computer restarts after a crash.

I think this feature was built to save time, but all it does is waste more time than it's worth, because whenever the computer restarts from a crash I usually just restart it once more (this time with "Reopen apps" disabled) just to get to a workable state. The problem is it'll keep spawning apps and preventing the restart from happening.

Disabling this feature would prevent me having to restart after a crash altogether. Is there a way to stop OS X from doing this?

2
  • Do you actually want us to help you getting rid of the errors ?
    – Ruskes
    Commented May 7, 2014 at 0:25
  • 7
    @Ruskes crashes could occur for many reasons. The question is valid on it's own
    – hmedia1
    Commented Jul 31, 2019 at 23:41

5 Answers 5

31

Permanently prevent macOS High Sierra from reopening apps after a restart

Works in macOS El Capitan, Yosemite, Sierra, High Sierra.

Solution: deny OS X access to the file it uses to store your session state. It prevents reopening apps even after reboot/shutdown from Terminal, from AppleScript, and system crash.

GUI method

  1. Open Finder
  2. Cmd+Shift+G (Go to folder)
  3. Copypaste ~/Library/Preferences/ByHost/ and confirm
  4. Find the file starting with com.apple.loginwindow
  5. Doubleclick (opens in TextEdit)
  6. Remove all content and save the empty file. An additional confirmation dialog may appear.
  7. Right click, Get Info
  8. Lock the file (check the checkbox)

GUI method (undo)

If you wish to undo this change later and re-enable the feature, simply delete this file and the OS will recreate it.

  1. Open Finder
  2. Cmd+Shift+G (Go to folder)
  3. Copypaste ~/Library/Preferences/ByHost/ and confirm
  4. Locate the file starting with com.apple.loginwindow
  5. Simply delete it

CLI method

  1. Open Terminal.app
  2. Make the file owned by root (otherwise the OS will just replace it)

    sudo chown root ~/Library/Preferences/ByHost/com.apple.loginwindow*
    
  3. Remove all permissions, so it can't be read or written to

    sudo chmod 000 ~/Library/Preferences/ByHost/com.apple.loginwindow*
    

CLI method (undo)

  1. Re-enable "reopen all apps" after login

    sudo rm -f ~/Library/Preferences/ByHost/com.apple.loginwindow*
    
4
  • 4
    Thank you for this great answer! It works well and does not require any user-intervention, such as holding down the [Shift] key when the system is restarting, and is perfect for unattended systems such as those used to support kiosks or information displays which may need to run their own predetermined startup sequence that can be complicated by the system restarting apps in a different order during an automatic login after a power outage.
    – bluebinary
    Commented Dec 18, 2018 at 20:34
  • 2
    @babca: for the cli method you might want to add purging the contents of the file as the first step, e.g.: echo > ~/Library/Preferences/ByHost/com.apple.loginwindow*
    – ccpizza
    Commented Jun 23, 2020 at 22:00
  • It worked for me in big sur
    – abumalick
    Commented May 10, 2021 at 8:56
  • 1
    @ccpizza bash does not support redirections onto patterns that match multiple files and will throw an ambiguous redirect error. Use echo | tee ~/Library/Preferences/ByHost/com.apple.loginwindow* instead.
    – kouwei32
    Commented May 4, 2023 at 21:15
6

I found @babca's approach works well, but on macOS Catalina for me it was slightly different. I had two com.apple.loginwindow.*.plist files in ~/Library/Preferences/ByHost/ and they were not plain text - com.apple.loginwindow.AB6XXXXX-XXXX-XXXX-XXXX-XXXXXXX5291.plist and com.apple.loginwindow.111XXXXX-XXXX-XXXX-XXXX-XXXXXXXXAC43.plist.

So I did the following two steps for each file:

Opened (⌘-O) each Finder into XCode (the default I think in Catalina), removed all the entries under TALAppsToRelaunchAtLogin, and saved the file.

enter image description here

Got Info (⌘-I) for each in Finder then check Locked checkbox. Note the preview box shows an empty <array/> inside TALAppsToRelaunchAtLogin.

enter image description here

To undo this change, repeat just the last step for each file but uncheck the Locked checkbox.

3

I introduce a different solution to satisfy a few additional requirements of my own that make it more versatile. The requirements are:

  1. It must be from the command line so I can copy and paste rather than clumsily click through a UI.
  2. It must be something that can be put in a for loop so I can modify every user on a machine. (DevOps anyone?) Additionally the code should still be able to stand alone, not requiring a for loop, so an end user can run it themselves for themselves.
  3. It must be able to handle the home directory being in a non-standard location.

With the help of code located here, I came up with the following, which works in sh and bash on Catalina and Big Sur at minimum...

# set user name, machine uuid, and home dir
someUser=$(stat -f%Su /dev/console)
machineUUID=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}')
homeDir=$(dscacheutil -q user -a name ${someUser} | grep 'dir:' | awk '{print $2}')

# delete the plist array
/usr/libexec/PlistBuddy -c 'Delete :TALAppsToRelaunchAtLogin' ${homeDir}/Library/Preferences/ByHost/com.apple.loginwindow.${machineUUID}.plist

# make the file readonly
chflags uimmutable ${homeDir}/Library/Preferences/ByHost/com.apple.loginwindow.${machineUUID}.plist
1
  • Works great on an old High Sierra "music" macmini. Now it's just like a CD player, ready in seconds. Thanks a lot. Commented Jun 2, 2022 at 9:16
1

Try holding down Shift when you see the login window and release it when the Dock appears.

This prevents items in your login items from starting when you log in but doesn't prevent apps that are resumed.

3
  • I have no idea why safe login was downvoted here. This is a quick and elegant solution to then get back in and make permanent changes.
    – bmike
    Commented Dec 16, 2017 at 0:32
  • It's possible it was downvoted because it doesn't work reliably. It never works for me.
    – rptb1
    Commented Dec 5, 2020 at 14:40
  • @bmike because like the answer even says: It doesn't prevent apps from reopening. That is exactly what the OP asked, and that's exactly what this answer does not address
    – hmedia1
    Commented Jun 7, 2021 at 23:09
1

Just a note for the CLI method... Works perfectly in El Cap, but upon upgrading to High Sierra, it no longer worked for me.

After chown root and chmod 000, I watched in the finder as the system recreated and populated a new file, and reverted ownership/permissions.

Obviously, this should NOT be possible, and I have no idea why this was allowed on a root-owned file. I even created a .lockfile to try to prevent this.

The only way I was able to get it to work (and stick) was by getting info on the file after setting perms and checking the "Locked" box.

I WOULD like to know how/why the system was bypassing chown/chmod perms on a root owned file. I suspect that chflags needs to be run for the CLI instructions to work in >High Sierra?

1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Alper
    Commented Jan 23, 2023 at 11:04

You must log in to answer this question.

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