How to turn off reopen projects on Xcode launch In Xcode 4.1 & later
Asked Answered
S

5

23

In Xcode 4.1 to present (4.2.1), if I close Xcode without first closing the project, the project will be automatically reopened the next time I launch Xcode. Previously I would have gotten the Welcome Screen. Is there a way to change this so that the Welcome Screen is launched instead?

Sesquipedalian answered 2/8, 2011 at 23:58 Comment(1)
Thanks for asking this. It's been driving me mad.Carcinoma
A
8

I did not have this trouble after disabling the 'Restore windows when quitting and re-opening apps' in the System Preferences.

System Preferences -> General -> Number of recent items section

Here you can find a checkbox to disable the feature.

However, if you force quit X-code, it will try and launch the projects that were open. Hope this helps.

Aztec answered 4/2, 2012 at 19:45 Comment(1)
WHY is it accepted as a correct answer?! It doesn't solve the problem and adds additional problems - Xcode not only continue to reopen projects but also doesn't show the list of recent projects you worked!Maryjomaryl
P
21

Don't want Xcode to second guess you so much?

I found an Xcode specific fix on Daniel Tull's blog, he credited it to "Pete". The link to his blog below describes doing the same task from the Finder.

XCode stores its prior window state here when it quits:

~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState

If you empty that folder and lock it, when you quit Xcode, it cannot write into the folder, but will simply quit gracefully. Subsequently, if you start Xcode directly, it opens nothing; Double clicking on a project file will open ONLY that project. It's exactly the behavior i want, and other apps will still obey the 'Restore windows when quitting and re-opening apps' General Preference.

I assume this trick would work selectively for other apps which use the "Saved Application State" folder, though some might complain if they can't write their state on the way out. You can probably accomplish this using unix permissions as well, but I only tested it using HFS locking on Lion with Xcode432.

Here are shell commands to this all in one go, set to be verbose and timid while doing so. You can just paste the whole block into a command terminal. This should work fine even if Xcode is running, but since Xcode4 swoons away on the flimsiest excuse, it's probably better to quit it first.

#----------
#show the current contents:
ls -al ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState/*
#just in case, unlock the folder, using the HFS-specific lock mechanism:
chflags -vv nouchg ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
#Empty the folder, asking for permission on each file (type 'y', then <enter> for each)
rm -ivd ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState/*
# Finally lock the folder so Xcode can't save its window state in the future:
chflags -vv uchg ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
# ----------

http://danieltull.co.uk/blog/2011/11/07/preventing-xcode-4-on-lion-reopening-windows/

Prussia answered 30/3, 2012 at 4:10 Comment(3)
Thank you, this saved me (when all other solutions I tried failed) after an hour of pure frustration.Scallion
The only fix that helped me. Thank you!Vigorous
This should be the selected answerMckale
L
8

Short version: ⌥⌘Q.

Pressing the option/alt key (AKA ⌥) when you quit does the trick. From the keyboard, ⌥⌘Q. From the menu, ⌥ changes "Quit Xcode" to "Quit And Discard Windows".

I still wish I knew a setting to do this by default (or better, reverse it, so ⌥ would cause Xcode to "Quit and Keep Windows"). For nefarious rejiggering, I also looked for "Quit And Discard Windows" under Xcode key bindings; no luck.

Lotic answered 4/9, 2011 at 14:59 Comment(2)
Brilliant. Default would be better, but this is good enough! My life improves just a little bit.Carcinoma
@thoughtadvances I can understand adding a comment here, but downvoting an Xcode how-to answer from 2011?Lotic
A
8

I did not have this trouble after disabling the 'Restore windows when quitting and re-opening apps' in the System Preferences.

System Preferences -> General -> Number of recent items section

Here you can find a checkbox to disable the feature.

However, if you force quit X-code, it will try and launch the projects that were open. Hope this helps.

Aztec answered 4/2, 2012 at 19:45 Comment(1)
WHY is it accepted as a correct answer?! It doesn't solve the problem and adds additional problems - Xcode not only continue to reopen projects but also doesn't show the list of recent projects you worked!Maryjomaryl
P
1

For Xcode Version 6.3 (6D570)

~/Library/Saved Application State/com.apple.dt.Xcode.savedState

Pyridoxine answered 24/4, 2015 at 13:1 Comment(0)
J
0

I have created a reusable script based on @Taryn answer so that you can run it any time you run into the issue. Note that I have commented the part which prevents xcode from saving state in the future. If you need it simply un comment. Below are few steps you need to have your script up and running just like other standard bash commands.

  1. Go to your home directory.

    cd

  2. Create a hidden custom .bash commands file for your custom functions.

    touch ~/.customBashCommands.sh

  3. Open the file using any of your preferred editors.

  4. Add the function to do the magic by pasting the following content.

#!/bin/bash

# A script to Remove Xcode last saved state, It's very useful if there is a bug preventing Xcode from opening.
# source: - https://mcmap.net/q/427031/-how-to-turn-off-reopen-projects-on-xcode-launch-in-xcode-4-1-amp-later
function restoreXcodeOrignalState() {
 echo '🚀 Preparing to remove Xcode Saved state...\n\n'
echo 'List of saved state to be removed 👇...\n'
ls -altr ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState/*
echo '\n\n'
#just in case, unlock the folder, using the HFS-specific lock mechanism:
echo 'Unlocking the folder using HFS-specific lock mechanism...\n'
chflags -vv nouchg ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
echo '\n\n'
echo 'Emptying Xcode saved state please accept if asked for permission...\n'
#Empty the folder, asking for permission on each file (type 'y', then <enter> for each)
rm -ivd ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState/*
echo '\n\n'
echo '🚀 Successfully finished the job!, You should be ready to use Xcode now 💪'


# Finally lock the folder so Xcode can't save its window state in the future:
#Uncoment the following line if you want to prevent xcode from saving state anymore.
#chflags -vv uchg ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState

}
  1. For the function to be available, Tell bash the location by doing the following steps.

    i). Open bash profile

          open .bash_profile 
    

    ii) Scroll to the bottom or any place and add the following line. to indicate your custom source file.

     source ~/.customBashCommands.sh
    
  2. In the command line refresh your newly .sh file as well as .bashrc and call the magic function.

    i) Refresh your new custom .sh file. Note If you named it different use your name instead.

       source ~/.customBashCommands.sh
    

    ii). Refresh bashrc file

      source ~/.bashrc
    

    NOTE: If you are using zsh check my answer for linking your zsh file with bash [here]1

  3. Finally, call your function just like any other bash functions any time like so: -

    restoreXcodeOrignalState
    

Conclusion:

I named my function as restoreXcodeOrignalState so if you named something different just follow the above steps with the name changed.

Jacks answered 27/9, 2020 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.