Extract HTML with Applescript & Automator

Hello, beautiful nerds!

I’m wanting to extract html from selected text in a web browser to my clipboard using an Automator service. I’m assuming this would require an AppleScript? Any help would be greatly appreciated!

Many thanks!

You can use both Automator as well as Applescript for this, but the Automator route is the easiest and fastest way.

  1. Open Automator
  2. Choose Service in the New workflow dialogue
  3. Choose “Receive selected text in any application” at the top (it should be default)
  4. Add the action “Copy to Clipboard” in the Library on the left

Save the workflow - now you’re able to run it from the Services menu.
I recommend assigning it a keyboard shortcut in System Preferences

1 Like

Thanks! Do you know a way to copy the background HTML as you copy it to the clipboard from a web browser?

You’ll probably need JavaScript to read from the DOM - see https://stackoverflow.com/questions/1335252/how-can-i-get-the-dom-element-which-contains-the-current-selection

There was a Firefox extension that used to do this but it no longer works.

1 Like

I think the underlying html could be a bit involved for a copy-paste from what you’re presented as a user. You could try the developer menu.

1 Like

Thanks, all! @JohnAtl, I think that’s probably the best option for me at this point. Thanks again.

1 Like