Shortcut or way to use code, to do anything at all with the item currently highlighted by Command+F

applescriptjavascriptkeyboardsafari

Title pretty much says it all. Also if anyone knows how to drag and drop something into a browser using any language or command(s), please share.

To be clear i'm talking about something like this:

  1. Press command+f
  2. Type in "the"
  3. (Insert magic hotkey, or bit of code, here, that does anything at with the word currently highlighted by command+f)

This could be used to click a link, for instance, or highlight the first word in a sentence (if you could use the command to do 2 clicks in quick succession) (at which point you could use shift+arrow keys to highlight the rest of the sentence, or the other commands to highlight by more than one character at a time, like shift+command+arrow keys)

As far as i know no such shortcut exists, but i don't see why, (so maybe one does exist and i'm just not aware of it).

Best Answer

If you select text in Safari (your example) Accessibility Inspector will list among Attributes:

  • "Passive" text . . AXRole: AXStaticText   /   AXValue: [text of a whole paragraph]
  • Link . . . . . . . . . . AXRole: AXStaticText   /   AXValue: [link name]

There's not very much functionality to detect there, is it?
Selected text in TextEdit on the other hand will display:

  • [Any text] . AXRole: AXTextArea   /   AXValue: [Whole text]   /   AXSelectedTextRange: [value]
  • [Link] . . . . AXRole: AXLink   /   AXRoleDescription: Hyperlink   /   AXURL: [its URL: http://...]

In Safari not too much can be done with highlighted text. Other programs -TextEdit!- that support accessibility more naturally, CAN be manipulated to a higher degree.

If you look at the hierarchy of a quite common button ("edited" on this page) it will reveal itself as:

AXStaticText ["edited"] / AXLink / AXGroup / AXWebArea / AXScrollArea / AXGroup / AXGroup / AXTabGroup / AXSplitGroup / AXWindow:AXStandardWindow / AXApplication

Doesn't sound very inviting to me, searching for a simple button ...
If I had to do a search I'd rather look into a Safari-document's source, text or URL, all of which are accessible, see: Safari's sdef file.