If anyone googles how to do this, here is the solution we found, it works with unsaved windows (hence the "untitled", you would have to change that depending on your use)

----------

In the command, execute the system comand (ours is Ruby, so backticks)
`osascript switch_windows.applescript`

----------

Then in your Support directory, the file: switch_windows.applescript

tell application "TextMate"
    activate
end tell
tell application "System Events"
    set found_window to false
    set all_windows to every window of process "TextMate"
    repeat with w in all_windows
        if name of w contains "untitled" then
            set editor_window to name of w
            set found_window to true
        end if
    end repeat
   
    if found_window then
       
        tell process "TextMate"
            tell menu bar 1
                tell menu bar item "Window"
                    tell menu "Window"
                        click menu item editor_window
                    end tell
                end tell
            end tell
        end tell
    end if
end tell