Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4.1 behaviours - automate closing a tab?

I have my behaviours set up so that on successfully running a build, Xcode will open a custom debug window. I would like to then close this window when the run completes, however I cannot see an option for this. The best I can manage is returning focus to my main window without closing the debug window.

I have a two monitor setup and most the time use the second monitor for the Xcode organiser. Obviously the debug window is of more use to me when running the application, however I would like to have my organiser back on top afterwards.

Is there any 'Close Tab' behaviour or similar in Xcode 4.1?

Thanks

Update:

Just to say that I've filed a feature request with Apple. Since most of the other behaviours have options (a pop-down menu) to show/hide, it seems only natural that this should be an option for tabs/windows also.

like image 489
Stuart Avatar asked Aug 27 '11 04:08

Stuart


2 Answers

I developed an Xcode plugin (Code on Github) that closes the debug window automatically after the debug session has ended. The plugin was developed and tested with Xcode 4.2.1 but should work with 4.1.

Usage

  1. Download "Xcode Auto Close Debug"

  2. Unzip it.

  3. Move XcodeAutoCloseDebug.xcplugin to ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/

  4. Restart Xcode

  5. Open menu "Xcode" -> "Preferences" -> "Behaviors" -> "Run Starts".

  6. Activate "Show tab" and set the tab name "XcodeAutoCloseDebug" (this exact name is important!) Setup Screenshot

  7. Run the executable and detach the debugger window (drag the tab out of Xcode to create an own window).

  8. Stop the executable and the window should close automatically.

... let me know if you experience any problems.

like image 164
Lars Schneider Avatar answered Oct 17 '22 20:10

Lars Schneider


You can run a shell script when run completes (don't forget to make it executable) :

#!/bin/sh
osascript ~/Documents/close-xcode-tab.scpt &

And the I use the AppleScript Editor to create the scpt file :

tell application "System Events"
    tell application "Xcode" to activate
    tell process "Xcode"
        tell menu bar 0
            click menu item "Close Tab" of menu "File"
        end tell
    end tell
    #keystroke "w" using {command down}
end tell

It will take 1-2 seconds to close the tab (but if you edit the script to only send the keystroke, it'll close quickly). The limits are that we can't be sure to close the "good" tab as xcode4 don't let retrieve tab name (it's possible with safari).

like image 32
ıɾuǝʞ Avatar answered Oct 17 '22 20:10

ıɾuǝʞ