In a script I'm trying to find the Terminal.app window containing a specific tty device and raise that window to the top. Here's what I have in Applescript so far:
tell application "System Events"
set foundWin to false
if (name of processes) contains "Terminal" then
tell application "Terminal"
set theTabs to first tab of every window where tty is "$(tty)"
repeat with theTab in theTabs
if class of theTab is tab then
set theWin to (first window whose tabs contains theTab)
set selected tab of theWin to theTab
set foundWin to true
end if
end repeat
end tell
end if
if foundWin then
--RAISE THE WINDOW?!
end if
end tell
Where I'm getting stuck is the "raising the window" part.
Here are some things that are not quite what I want:
set frontmost of theWin to true
-- this brings the window to the front of the group of Terminal.app windows but doesn't raise it above any other windows.
tell application "Terminal" to activate
-- this brings every Terminal window to the front in a big stack. I just want the one window.
tell application "System Events"
set theSysWin to first window of process "Terminal" whose name is (name of theWin)
perform action "AXRaise" of theSysWin
end tell
This almost does it, but what it does is to raise the terminal window to the #2 position, still underneath the active window (if the active app is something other than Terminal.app.)
click theSysWin at {10,50}
-- doesn't seem to do anything.
click first static text of theSysWin
-- doesn't seem to do anything.
Is there a way to do this? It doesn't have to be in Applescript.
EDIT I did find this web page ( http://blog.coriolis.ch/2008/03/04/bring-any-window-to-the-front/ ) quoting an Obj-C/Cocoa call:
SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
I'm not familiar with either ObjC or Cocoa, and this is (ultimately) getting invoked from a shell script, so not sure where to go from there.