在 Xcode 4.1 到现在 (4.2.1) 中,如果我在没有先关闭项目的情况下关闭 Xcode,则下次启动 Xcode 时项目将自动重新打开。以前我会得到欢迎屏幕。有没有办法改变这一点,以便启动欢迎屏幕?
5 回答
不想让 Xcode 如此猜测你?
我在 Daniel Tull 的博客上找到了 Xcode 特定的修复程序,他将其归功于“Pete”。下面指向他的博客的链接描述了从 Finder 执行相同的任务。
XCode 在退出时将其先前的窗口状态存储在这里:
~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
如果您清空该文件夹并锁定它,当您退出 Xcode 时,它无法写入该文件夹,而只会优雅地退出。随后,如果你直接启动 Xcode,它什么也不会打开;双击项目文件将仅打开该项目。这正是我想要的行为,其他应用程序仍将遵循“退出和重新打开应用程序时恢复窗口”的一般偏好。
我认为这个技巧可以选择性地适用于使用“保存的应用程序状态”文件夹的其他应用程序,尽管有些人可能会抱怨如果他们不能在退出时写下他们的状态。您可能也可以使用 unix 权限来完成此操作,但我仅使用 Xcode432 对 Lion 使用 HFS 锁定对其进行了测试。
这里是所有这些的shell命令,在这样做时设置为冗长和胆怯。您可以将整个块粘贴到命令终端中。即使 Xcode 正在运行,这也应该可以正常工作,但是由于 Xcode4 以最脆弱的借口消失了,最好先退出它。
#----------
#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/
在系统偏好设置中禁用“退出和重新打开应用程序时恢复窗口”后,我没有遇到这个问题。
系统偏好设置 -> 常规 -> 最近项目数部分
在这里您可以找到一个复选框来禁用该功能。
但是,如果您强制退出 X-code,它将尝试启动打开的项目。希望这可以帮助。
短版:⌥⌘Q。
退出时按 option/alt 键(AKA ⌥)就可以了。从键盘,⌥⌘Q。从菜单中,⌥ 将“退出 Xcode”更改为“退出并丢弃 Windows”。
我仍然希望我知道默认情况下执行此操作的设置(或者更好的是,将其反转,所以 ⌥ 会导致 Xcode “退出并保留 Windows”)。对于邪恶的重新调整,我还在 Xcode 键绑定下寻找“退出并丢弃 Windows”;没运气。
对于 Xcode 版本 6.3 (6D570)
~/Library/Saved Application State/com.apple.dt.Xcode.savedState
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.
Go to your home directory.
cd
Create a hidden custom .bash commands file for your custom functions.
touch ~/.customBashCommands.sh
Open the file using any of your preferred editors.
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://stackoverflow.com/a/9936904/7551807
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
}
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
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
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.