Xcode 3 and Interface Builder 3 don’t like it when you switch files out from underneath them, like what happens when you switch branches in git and mercurial.
Here’s a handy AppleScript that will remember and close all your open Xcode projects and IB documents. Run it again, and all your projects+docs will be reopened, ready again for action.
tell application "System Events"
if exists file ".xcpushpop.plist" of home folder then
-- pop/restore
set plist to property list file "~/.xcpushpop.plist"
set xcList to value of property list item "xc" of plist
set ibList to value of property list item "ib" of plist
repeat with xcItem in xcList
tell application "Xcode" to open xcItem
end repeat
repeat with ibItem in ibList
tell application "Interface Builder" to open ibItem
end repeat
delete file ".xcpushpop.plist" of home folder
else
-- push/save
set openedXcodeProjects to {}
set openedIBDocs to {}
if my isRunning("com.apple.Xcode") then
tell application "Xcode"
repeat with p in project documents
set openedXcodeProjects to openedXcodeProjects & path of p
end repeat
close every project document
end tell
end if
if my isRunning("com.apple.InterfaceBuilder3") then
tell application "Interface Builder"
repeat with d in documents
set openedIBDocs to openedIBDocs & path of d
end repeat
close every document
end tell
end if
set plist to make new property list file with properties {name:"~/.xcpushpop.plist"}
make new property list item at end of property list items of contents of plist ¬
with properties {kind:list, name:"xc", value:openedXcodeProjects}
make new property list item at end of property list items of contents of plist ¬
with properties {kind:list, name:"ib", value:openedIBDocs}
end if
end tell
on isRunning(bundleID)
tell application "System Events"
set procList to every process whose bundle identifier is bundleID
end tell
return procList is not {}
end isRunning