iKluge

Random thoughts of a software developer

Getting rid of Lion’s application restore

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
About these ads

25 responses to “Getting rid of Lion’s application restore

  1. drbroom August 24, 2011 at 5:45 pm

    Hex:

    You are my new god (ok demigod)! Thank you for finding what I couldn’t…

    db

  2. Matthew (@mattonthemoon) August 24, 2011 at 10:06 pm

    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.

  3. lenny277 August 24, 2011 at 10:56 pm

    This is not working for me in either form.

  4. Matthew (@mattonthemoon) August 24, 2011 at 10:34 pm

    It’s now working, thank you!

    No more having to uncheck when i want to shutdown.

    Thank you thank you thank you!

  5. levent99 August 25, 2011 at 3:48 am

    working rwboot and shutdown.

    how to use this for logout ?

  6. Pingback: Disable “Reopen Windows When Logging Back In” in Mac OS X Lion Completely

  7. dg September 1, 2011 at 2:36 pm

    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

  8. Matthew (@mattonthemoon) September 2, 2011 at 10:30 am

    disabling with
    sudo defaults delete com.apple.loginwindow LoginHook
    does not seem to work.

  9. lhagan September 3, 2011 at 7:31 pm

    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!

    • hexbrain1 September 6, 2011 at 8:55 am

      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.

  10. Pingback: Mac os x Lion: disattivare l’apertura automatica delle applicazioni - SlideToMac

  11. James Moss (@jimbomoss) September 12, 2011 at 9:38 am

    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)

  12. Chase Sillevis (@DeviaVir) September 12, 2011 at 10:01 am

    Could you mirror this somewhere else?

    As it currently stands.. pastie.org is down.

  13. Justin September 13, 2011 at 4:52 am

    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

    • Justin September 13, 2011 at 4:54 am

      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

    • Justin September 19, 2011 at 4:33 am

      Actually, after initially unticking the checkbox at shutdown (but not since), the script now seems to work perfectly…

  14. Pingback: Disattivare l’apertura delle applicazioni su Lion: vediamo come fare | iSpazio MAC

  15. Pingback: Tuto CrazyMac : Désactiver l’ouverture automatique des applications au démarrage de Mac OS X Lion - CrazyMac

  16. rich12345 October 6, 2011 at 3:35 pm

    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!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: