The tab bar and its contained tabs can be read by AppleScript using System Events and UI-Scripting. Something like this:
tell application "System Events"
tell application process "Google Chrome"
tell (first window whose subrole is "AXStandardWindow")
tell group 1
tell group 1
tell group 1
tell group 1
tell tab group 1
return {position, size}
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
And yes β you can get the position and size of the buttons as well.
An alternative could be a gesture trigger. Short movement with the mouse to the right while pressing cmd (with a modifier it is safer) The mouse can be anywhere.
Have you ever written a macro that intercepts a mouse click using the KM trigger called "This USB device key... ... is tapped twice?"
If you have, you will realize that KM does not intercept (and stop) the mouse event (ie, tapping twice) which is the main problem.
What you probably need is for KM to intercept and STOP the double click event. While KM can detect and intercept the event, it can't stop it. KM has a "hotkey trigger" which DOES intercept keys, but it does not have a "hotmouse trigger" to intercept mouse clicks. Maybe it should have hotmouse triggers, but it doesn't. I suspect that the lag would be frustrating to users.
Since I have no idea what Chrome does when you double click on a tab, I can't tell if this is going to stop you from writing a macro that does what you want. Ok,... I did a quick AI search and found that double clicking on a tab probably does nothing (am I correct?), but double clicking in a blank area of the tab bar DOES do something. Is double clicking on the empty area of the tab bar something you need to remain operational?
I have accomplished similar things in the past, by writing code in KM that determines the position of things on the screen based on the number of CR's in the returned OCR. But this is tricky, and will require a lot of testing, which I can't do because I will not install Chrome. So if you are a good programmer I can set your sail in the right direction so you can accomplish this, if you want to.
Even if you do write the code to do this, it will be finicky, and will only work for specific screen resolutions. You will not be able to change your resolutions (or the size of the text in your tabs) once you get this code working. Is that acceptable?
It is still an issue if you want to be able to double click on the empty area to the right of the tabs. I didn't see an answer from you to that question. Do you need to retain that functionality?
It's easy to determine the text in the general area of the mouse, but knowing exactly where the tab is to fetch only the text in that tab is the tricky part. AppleScript may work here for Safari, but you don't want to use that browser.
Google doesn't support AppleScript very well. As far as I know, the only browser that opens itself up to AppleScript in a big way is Safari. So you can complain to Google about their lack of AppleScript support. But as I explained above, if you are willing to to a lot of math/logic calculations, you can probably use OCR to determine the positions of the tabs, and then use OCR again to find the text in the tab that the mouse is over. If you are interested in working for about a week to do the calculations to make this work, I can give you some guidance.
Here's a wild idea...I'm not sure if it's feasible.
detect that a double-click happened
determine if it happened in the tab area (look at the Y coordinates relative to the window)
if #1 & #2 are true, find image (i.e. look for the "x" on the right side of the tab you clicked on). Obviously you'll want to limit the search area so it doesn't overshoot
if the image is found, click it, thereby closing the tab
It's kind'a convoluted, but in theory I think it'd work.
I get what you are saying. It's not a bad idea, but you are faced with the same problem I described above, which is that KM can't intercept a mouse click, it can only detect that a mouse click happened and that the app handled the mouse click. The consequences of this were described in one of my posts above.
I looked for a screen shot of Chrome's tabs and found that the "X" comes in different shades of grey. So your Find Image code is going to have to search for all three shades, and pick the leftmost one. Find Image has always had a little difficulty searching for a small image without contrasting colours, which may also be a challenge.
Ah, I mistakenly assumed that if it could detect that the mouse click happened that it could also get the coords.
How about a different way to approach this maybe? Instead of double-clicking on the tab, how about hovering over the tab and hitting a hot key (maybe cmd-shift-w)?
Then KM can:
get the mouse coords
determine if it's within the tab area
click once where the mouse to activate that tab
send cmd-W
Or maybe continue using cmd-W, but just make it "smarter"...set KM to intercept cmd-w...
Steps 1-4 are still the same, with the exception that if the mouse coords isn't within the tab area, send cmd-W anyways (i.e. act as if the macro didn't exist).
Your latest idea is much more viable. You should try implementing it. But there are a few problems you will face. One problem is what happens if step 3 unintentionally clicks on the close window X-button? Another problem is what happens if there's only one tab open, which means the tab bar is not visible? And of course the final issue is that this solution doesn't meet the user's requirements. On this website we try our best to meet the user's requirements no matter how inappropriate they seem to be.
Regardless of approach, this is going to be the sticking point: There's no easy, fast, automatic, painless way to figure out if the mouse is within a tab area.
If your main goal is closing background tabs, I'd approach this in a different way: Get a list of open tabs, present them in a list, and close any you want by selecting (multi selecting even), then pressing Enter.
Here's a very rough macro that seems to workβyou can use Shift and/or Command to select multiple items; press Enter and those tabs are closed.