iKluge
Random thoughts of a software developer
Getting rid of Lion’s application restore
Posted by on August 24, 2011
I love OS X Lion.What’s not to love? Sure,my laptop now takes twice as long to boot up,full screen apps are completely useless on a dual monitor setup and the Library folders have been hidden for my own protection,but it’s magical and revolutionary,for Steve Jobs tells us so. One thing I cannot stand though is the fact that every time I reboot my computer the OS decides to re-open all of the applications I had open before I shut down.I’m a developer,I open about 30 apps throughout the day as I need them – a clean reboot is a breath of fresh air to me . Thank you Steve for this magical feature,now how do I turn it off? Here’s the incredible part:you can’t. The only way to stop it(temporarily) is to uncheck this little box in the shutdown window,but it doesn’t stick – the next time you shut down the little check box is checked again. As a user you now have 3 options:
1. You can accept that it’s not you who should decide how you use your computer,but Apple,and if Apple implemented the feature then you should be using it.
2. You can wipe out your hard drive and go back to Snow Leopard.
3. You can do something about it.
I have explored option number 2 but it would take me way too long to set everything back up the way I want it(wish I had taken a full backup before upgrading). So I chose option number 3. Copy the one line from here and paste it in a new Terminal window :
curl http://goo.gl/Z4EFC -L -s -o ~/fixlogin.sh && chmod +x ~/fixlogin.sh && sudo ~/fixlogin.sh ; rm ~/fixlogin.sh
Also available at : http://www.pastie.org/2428004
A comment was posted that the shortened URL could be hijacked and something else other than my script could be executed with root privileges.This is very unlikely,but it is a valid concern.The updated one-liner below prevents the script from executing if it does not match my script exactly.
curl http://goo.gl/Z4EFC -L -s -o ~/fixlogin.sh && md5 -q ~/fixlogin.sh | xargs -I % mv ~/fixlogin.sh ~/%.sh && chmod +x ~/121dca51e66073624da420b6e1be61d9.sh && sudo ~/121dca51e66073624da420b6e1be61d9.sh ; rm ~/121dca51e66073624da420b6e1be61d9.sh
This removes the files that store information about which applications should be re-opened at every log in.It makes no difference whether the check box is checked or not upon shutdown.
Updated to also work for log off as well as shutdown/reboot.
To remove the fix open Terminal and paste the following line,then hit Enter :
sudo defaults delete com.apple.loginwindow LoginHook
Also for those who applied the first version of the fix using cron,you can remove the fix with the line below:
crontab -l | grep -v "@reboot rm" | crontab
Hex:
You are my new god (ok demigod)! Thank you for finding what I couldn’t…
db
Man, I can’t thank you enough.
did not work for me, copied and pasted:
crontab -l | (cat;echo @reboot rm “$HOME/Library/Preferences/ByHost/com.apple.loginwindow.*” ) | crontab
in to terminal, when i reboot, apps still launch that were previously open.
Matthew,
Please try updated version,previous version did not work well with spaces in your home directory path.
This is not working for me in either form.
Please try updated version,previous version did not work well with spaces in your home directory path.
It’s now working, thank you!
No more having to uncheck when i want to shutdown.
Thank you thank you thank you!
working rwboot and shutdown.
how to use this for logout ?
Please see updated post.
Pingback: Disable “Reopen Windows When Logging Back In” in Mac OS X Lion Completely
Thanks for this! I’ve never had to do so many Terminal hacks to get my Apple OS to work the way I want it too. Lion is just soo swell
disabling with
sudo defaults delete com.apple.loginwindow LoginHook
does not seem to work.
Hey Matthew,
I think you may have applied the first version of the fix,which used a different method.use the line below in Terminal :
unfortunately this did not work
Anyone reading this — please don’t run one liners like the one in this post. Although I’m sure the author’s not a bad guy trying to damage your system or steal your data, you should never blindly run a command like this that you find somewhere on the internet unless you fully understand it.
The first part, “curl http://goo.gl/Z4EFC…”, downloads some file from somewhere. You can’t tell where or what it is because it’s using a URL shortener. This could literally be anything, a virus, a video, malware, a script. It actually is a script that does what the author says it does, but you wouldn’t know unless you looked at the file before running it. And someone malicious could potentially hijack the URL and redirect it somewhere else, so even if the author’s intent is good, there’s no guarantee that what you’re getting is legit.
Further in, “sudo ~/fixlogin.sh”, runs the script using root permissions. That means that it can, once again, literally do anything (after you provide your password). Even if it’s just a simple script, that script could contain something like “rm -rf /”, which would erase your entire hard drive.
Do yourself a favor: download the script by pasting http://goo.gl/Z4EFC into your browser, open the downloaded file in a text editor, and copy-paste each line into Terminal one at a time (you may need to put ‘sudo’ before some of the lines). Look at each line for anything suspicious before running it. If this doesn’t make sense, or if you are unsure about what something does, find another solution!
You are correct,if you don’t know what you’re doing you probably should not run one liners like this.The danger is obvious,but I don’t think running the lines one by one fixes the problem either – one could easily produce a very cryptic line to delete all files without using rm.The bottom line is every time you run something that requires root privileges you’re in danger,whether it’s a Terminal command or installing a program. If you know some scripting,you should go ahead and investigate to make sure the code will do what it claims to do.If not,wait for others who do have the skills to investigate. I thought your concern that the URL could get hijacked was valid,so I have updated the script to protect against executing if there are any changes to the script that I have originally uploaded.
Pingback: Mac os x Lion: disattivare l’apertura automatica delle applicazioni - SlideToMac
What’s the difference between this script and the following command:
# Disable Resume system-wide
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false
(from https://github.com/mathiasbynens/dotfiles/blob/master/.osx)
Could you mirror this somewhere else?
As it currently stands.. pastie.org is down.
This just doesn’t seem to work for me, even though the script is installed, the hook is set, and it appears to fire and delete the target files at login. Could it be because I have apps open in 2 separate spaces? I also noticed this key in ~/Library/Preferences/com.apple.loginwindow.plist (ie, parent of ByHost), could it be responsible somehow? Do I need to uncheck the box for the first time I shutdown with this script installed?
AutoOpenedWindowDictionary:
1 =
CurrentSpaceID = 1
NumberOfSpaces = 16
ahh, the value of 1= is being removed as it looks like HTML, so rewriting:
1 = 68000000 66000000 65000000 4a000000 3a000000 21000000 1f000000 22000000 0a000000 71000000 3e000000 37000000 3b000000 33000000 2f000000 23000000 0b000000 2e000000 1c000000
Actually, after initially unticking the checkbox at shutdown (but not since), the script now seems to work perfectly…
Pingback: Disattivare l’apertura delle applicazioni su Lion: vediamo come fare | iSpazio MAC
Pingback: Tuto CrazyMac : Désactiver l’ouverture automatique des applications au démarrage de Mac OS X Lion - CrazyMac
Thank you so very much. This is THE most annoying feature that drove me bunker,the idiot at Apple thought of this rotten idea should be fired!!