Created
February 9, 2012 09:34
-
-
Save wearhere/1778815 to your computer and use it in GitHub Desktop.
Keep your current source file open in Xcode after a run completes (a.k.a don't die in main.m)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# On alternate invocations, this script | |
# saves the path of the source file currently open in Xcode | |
# and restores the file at that path in Xcode. | |
# | |
# By setting Xcode (in Behaviors) to run this script when "Run Starts" | |
# and when "Run Completes", you can prevent it from switching to main.m | |
# when a run finishes. | |
# See http://stackoverflow.com/questions/7682277/xcode-4-2-jumps-to-main-m-every-time-after-stopping-simulator | |
# for a description of the problem and a bunch of solutions which don't work. | |
# We use the defaults system to save the source path. | |
# Change the domain to whatever you like. | |
DOMAIN="com.wearhere.keep_current_file_open" | |
KEY="savedSourcePath" | |
# The first time this script is invoked, this call will return a "does not exist" error. | |
# The second time this script it invoked, this call will return the saved source path. | |
# We copy stderr to stdout so that we can read both results using a single call. | |
savedSourcePath=`defaults read $DOMAIN $KEY 2>&1` | |
if [[ "$savedSourcePath" == *"does not exist"* ]]; then | |
# read path of current source file out of Xcode | |
sourcePath="`osascript << EOT | |
tell application "Xcode" | |
set windowName to (name of first window) | |
set currentFileName to item 2 of (words of windowName) | |
set currentSourceDocument to first item of (source documents whose name ends with currentFileName) | |
set currentSourceFile to (file of currentSourceDocument) | |
set currentSourcePath to (POSIX path of currentSourceFile) | |
end tell | |
return currentSourcePath | |
EOT`" | |
# save current source path | |
defaults write $DOMAIN $KEY "$sourcePath" | |
else | |
# open saved source path in Xcode | |
open "$savedSourcePath" | |
# clear saved source path | |
defaults delete $DOMAIN $KEY | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Xcode 4.2.1, at least, it seems that you can put ‘handle SIGKILL nostop noprint nopass’ into ~/.gdbinit (link). Even better!