Hi,
I need to set focus to some window identified by its title. I’ve looked around this forum, but couldn’t find anything.
I also tried different versions of
tell application "System Environment"
activate first window whose name is "window_name"
end tell
and that didn’t work. Also tried setting the variable AXFocused to true and again, no luck.
Thanks in advance,
-Andrew
I am running several firefox applications (i have a separate firefox icon for each on my dashboard) and each of them have multiple windows open (not tabs; so one is a parent and the rest are children). Obviously each window has its own title. I need to set focus to a specific window by title. I still can’t get this to work. Could anyone help out?
Thanks - I’ve actually looked through that thread before.
I’m sure there must be a solution - I’ve used the following script before to give focus
to some window from firefox as long as there’s only one firefox application open.
tell application "Firefox"
activate
set visible of first window whose name contains "some_name" to true
end tell
The problem is that I really don’t know applescript at all. For multiple running firefox
applications, I feel the strategy would be to:
iterate through all running firefox applications
for each, if it has a window with title equal to whatever_title_i’m_looking_for
set that window to be focused (I’m guessing set visible = true?)
That doesn’t really help as, like I said above, I don’t know applescript at all, and there aren’t any good sources to learn it,
so I simply don’t know how to do that. I’ve just been playing around with random scripts.
Could someone explain why the following script gives me the error “System Events got an error: Can’t make visible of every window of process id 51380225 whose visible = true and name ≠"Google" into type reference.” ?
on run
try
tell application "System Events"
set appList to (id of every process whose visible = true)
set firefoxAppList to (id of every process whose name = "firefox-bin")
end tell
tell application "System Events"
repeat with firefoxProcess in firefoxAppList
set windowList to (title of every window of process id firefoxProcess)
repeat with windowTitle in windowList
tell process id firefoxProcess
set (visible of every window whose visible is true and name is not "Google") to false
end tell
end repeat
delay 1
end repeat
end tell
on error err
tell me to activate
display alert "There was a problem running the script." as critical message err
end try
end run
also - how would i do something simple like get title of currently focused window whatever the app may be?
I think a stupid way I could solve my problem is just instruct the computer to hit ctrl+F4, then check which window
has focus and if its title matches the one i want, break, else keep going.
been mucking around with you last posted script, getting some where I think
on run
try
tell application “System Events”
set appList to (id of every process whose visible = true)
set firefoxAppList to (id of every process whose name = “firefox-bin”)
end tell
tell application “System Events”
repeat with firefoxProcess in firefoxAppList
set windowList to (title of every window of process id firefoxProcess) --as alias
--repeat with windowTitle in windowList
--tell process id firefoxProcess
--set (visible of every window whose visible is true and name is not "Google") to false
--end tell
if windowList contains "Google" then
tell application "Firefox"
set _new to get index of window "Google"
set index of window _new to 1
end tell
end if
--end repeat
delay 1
end repeat
end tell
on error err
tell me to activate
display alert "There was a problem running the script." as critical message err
end try
You can use code like the following to bring a window named SOME_WINDOW_NAME to the front for an app named SOME_APP:
tell application "System Events"
tell application process "SOME_APP"
perform action "AXRaise" of (first window whose name contains "SOME_WINDOW_NAME")
end tell
end tell
The ‘perform action’ command is a very useful one for UI Scripting.