I'm not quite clear on what you're asking, but I want to go the that tab (URL=http://127.0.0.1:52587/browser/) and display it (of course if the URL isn't opened, then need some error checking). BTW, the tab is named 'pgAdmin 4' if that helps.
I don't really get how this works. The URL is opened by an app pgAdmin 4, but the app's only interface is via the URL. The app is (also) creating a connection to the Postgres databases stored somewhere on my computer.
We still don't completely understand each other, but based on what you are saying I just wrote a macro that looks for the the existing tab (in safari) with the word "youtube" in the title and displays it. You could replace Youtube by "127.0.0.1" if I understand your problem correctly, which I'm not sure I do.
There's probably better ways to solve this problem than that, but for the moment I just want to know if this code does what you want. That is, this code looks for the tab containing a string and switches to it.
I apologize if I don't understand correctly. This is an attempt to understand the problem.
I think a screenshot would be helpful here. That's because there are different types of tabs. There are tabs at the top of a web browser, and tabs inside the web page itself. I'll bet that's where the communication problem lays here.
I tried the script. Maybe I typo'ed but I went right by the page in an endless loop. So need some error checking (which I would need if the page isn't opened anyway).
I won't if the "typo" is that when I copy the url from Safari to KM http:// is added but Safari doesn't show that (at least in my setup). Doesn't matter.
Sorry, the Group action does nothing, other than make it easier for me to take a screenshot.
Your screenshot shows the wrong key in the TYPE action box. But that's not really your fault because I accidentally left that TYPE action in there when it shouldn't have been there at all. Sorry, again. it doesn't actually break the macro, it just made it messy.
If it still doesn't work after you remove that action, it's probably one of two things:
The string you are using, "127.0.0.1:52587/browser/" is incorrect, or
The pause statement needs to be larger.
I think the mistake is your string because in your screenshot I do not see 52587 I see 61468. This is part of the reason I asked you to search for the string "127.0.0.1". But you added 15 extra characters. Try it my way, using "127.0.0.1", to make it easier to debug this.
There are some wizards on this forum that can answer most questions like this using AppleScript. But I'm not that skilled yet. If for any reason my solution doesn't work for you, we can press one of them for an AppleScript solution.
I hadn't noticed that the number changes. Lucky I had to restart it, so that error became apparent.
I removed the type action, but I use Cmd-Shift-Right Arrow to cycle through the tabs. Tab goes to any field that text can be entered in on the page. Control-Shift-tab works. I found that out looking for where I'd implemented Cmd-Shift-Right arrow. Of course when you're writing as I'm doing now in this textbox, some of the commands don't work.
Thanks again. I'll have to see how fast I can make it.
Final solution for anyone trying to figure this out. Although I need add error checking in case I start the macro without having the 127.0.0.1 opened. I had to quit KM engine to stop it. I assume I can wrap it in a until and stop after say 15 tabs:
It may be possible to avoid a pause statement if you simply compare successive tabs to make sure they are different. Once they are different you know you are on a new tab (rather than a pause statement). I didn't write the code to do that because that would have greatly complicated the issue for the moment. Do you see how it's possible to do this? Or maybe it's just not very important to gain another 5% speed and reliability.
tell application "Safari"
set topWindows to every window whose name is not ""
set numWindows to the number of topWindows
set didFind to false
set targetUrl to "https://chatgpt.com/"
repeat with x from 1 to numWindows
set numTabs to the number of tabs in window x
repeat with y from 1 to numTabs
set tabUrl to the URL of tab y of window x
if tabUrl contains targetUrl then
set didFind to true
tell window x to set current tab to tab y
end if
end repeat
end repeat
if didFind is false then
tell window 1 to set current tab to (make new tab with properties {URL:targetUrl})
end if
end tell
This has also helped me on occasion:
# This example will return both the URL and title for the frontmost tab of the active browser, separated by a newline.
# Keep in mind that by using `using terms from`, we’re basically requiring that referenced browser to be available on the system
# (i.e., to use this on "Google Chrome Canary" or "Chromium", "Google Chrome" needs to be installed).
# This is required to be able to use a variable in `tell application`. If it is undesirable, the accompanying example should be used instead.
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if (frontApp = "Safari") or (frontApp = "Webkit") then
using terms from application "Safari"
tell application frontApp to set currentTabUrl to URL of front document
tell application frontApp to set currentTabTitle to name of front document
end using terms from
else if (frontApp = "Google Chrome") or (frontApp = "Google Chrome Canary") or (frontApp = "Chromium") then
using terms from application "Google Chrome"
tell application frontApp to set currentTabUrl to URL of active tab of front window
tell application frontApp to set currentTabTitle to title of active tab of front window
end using terms from
else
return "You need a supported browser as your frontmost app"
end if
return currentTabUrl & "\n" & currentTabTitle