Xcode 4.1 behaviours - automate closing a tab?
Asked Answered
L

2

9

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.

Lallygag answered 27/8, 2011 at 4:51 Comment(3)
Perhaps via AppleScript?Sway
Though it pains me to say it, I don't have enough knowledge of AppleScript to produce such a script. One of the problems I foresee with this anyway is that in Xcode behaviours it opens a tab that I called "Debug" in a separate window, however the window title is not "Debug". I guess there is some internal state in Xcode which remembers that that window is in fact a 'tab' called "Debug"? How can I ensure that a script would bring the correct window to the foreground before closing?Lallygag
I also searched and didn't find anything in Xcode about closing tabs :(Georgetta
B
7

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.

Baldpate answered 25/12, 2011 at 10:22 Comment(0)
T
3

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).

Trustee answered 23/12, 2011 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.