You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

copy text without links in safari

When copying text from a web page in Safari that includes embedded links, and then pasting it in Messages, it includes the URLs in angled brackets. I would like it to stop including these URLs.


Just to make up an example, let's say I want to copy the following text on a web page:


"Hydrogen contains one proton."


It is a sentence with three links. Suppose I highlight it using the mouse cursor, then type cmd-c to copy it. When I paste it into a conversation in Messages, I get the following:


"Hydrogen contains <http://www.dictionary.com/browse/contain> one <https://en.wikipedia.org/wiki/1> proton <https://en.wikipedia.org/wiki/Proton>."


As you can imagine, that gets incredibly spammy when there are several links in the text, especially when the links are long. It becomes impossible to read the text, and it's a problem to have to go through and delete all the URLs one at a time every time I want to copy/paste some text. I would like for it not to include the URLs. How can I accomplish that?


I am using mac os x 10.12.4, Safari 10.1, and Messages 10.0 on a macbook pro from late 2016.


Thanks!

MacBook Pro (15-inch, Late 2016), macOS Sierra (10.12.4)

Posted on May 5, 2017 1:32 PM

Reply
Question marked as Top-ranking reply

Posted on May 7, 2017 7:13 AM

Here is a solution for removing HTML markup from a text string that is outlined in the section, “Working with HTML and URLs,” in the Apple Developer's Mac Automation Scripting Guide.


What I have done is create an Automator Service from the HTML removal AppleScript example in this guide. All that is needed is one Automator action that strips the HTML syntax from the selected text. So, in your example where you want to strip all HTML out of “Hydrogen contains one proton.” — the Automator service would put “Hydrogen contains one proton.” on the clipboard, and ready to paste into Messages, or any other application as just text.


When I saved the new Automator Service, I gave it the memorable name, “Remove HTML from Text.”


  1. Launchpad : Other : Automator

    New : Service : Choose.

  2. Drag and drop the Run AppleScript action to the right into the larger workflow window.
    1. Prior to Sierra, the Run AppleScript action is in the Automator Utility Library. With Sierra, it is found in the Automator Library.
    2. Select entire contents of AppleScript boilerplate, and remove.
    3. Copy/paste code from below into the Run AppleScript action window.
  3. Save...

    filename: Remove HTML from Text

  4. Quit Automator
  5. Select text in browser with known HTML links

    Safari menu : Services : Remove HTML from Text

  6. Paste plain text from clipboard into target application


-- Remove HTML from Text

-- Content must be selected before choosing this Service


on run {input, parameters}

set theText to (item 1 of input) as text

set the clipboard toremoveMarkupFromText(theText) as text

return

end run


on removeMarkupFromText(theText)

set tagDetected to false

set theCleanText to ""

repeat with a from 1 to length of theText

set theCurrentCharacter to charactera of theText

if theCurrentCharacter is "<" then

set tagDetected to true

else if theCurrentCharacter is ">" then

set tagDetected to false

else if tagDetected is false then

set theCleanText to theCleanText & theCurrentCharacter as string

end if

end repeat

return theCleanText

end removeMarkupFromText


User uploaded file

5 replies
Question marked as Top-ranking reply

May 7, 2017 7:13 AM in response to BrianRol

Here is a solution for removing HTML markup from a text string that is outlined in the section, “Working with HTML and URLs,” in the Apple Developer's Mac Automation Scripting Guide.


What I have done is create an Automator Service from the HTML removal AppleScript example in this guide. All that is needed is one Automator action that strips the HTML syntax from the selected text. So, in your example where you want to strip all HTML out of “Hydrogen contains one proton.” — the Automator service would put “Hydrogen contains one proton.” on the clipboard, and ready to paste into Messages, or any other application as just text.


When I saved the new Automator Service, I gave it the memorable name, “Remove HTML from Text.”


  1. Launchpad : Other : Automator

    New : Service : Choose.

  2. Drag and drop the Run AppleScript action to the right into the larger workflow window.
    1. Prior to Sierra, the Run AppleScript action is in the Automator Utility Library. With Sierra, it is found in the Automator Library.
    2. Select entire contents of AppleScript boilerplate, and remove.
    3. Copy/paste code from below into the Run AppleScript action window.
  3. Save...

    filename: Remove HTML from Text

  4. Quit Automator
  5. Select text in browser with known HTML links

    Safari menu : Services : Remove HTML from Text

  6. Paste plain text from clipboard into target application


-- Remove HTML from Text

-- Content must be selected before choosing this Service


on run {input, parameters}

set theText to (item 1 of input) as text

set the clipboard toremoveMarkupFromText(theText) as text

return

end run


on removeMarkupFromText(theText)

set tagDetected to false

set theCleanText to ""

repeat with a from 1 to length of theText

set theCurrentCharacter to charactera of theText

if theCurrentCharacter is "<" then

set tagDetected to true

else if theCurrentCharacter is ">" then

set tagDetected to false

else if tagDetected is false then

set theCleanText to theCleanText & theCurrentCharacter as string

end if

end repeat

return theCleanText

end removeMarkupFromText


User uploaded file

May 7, 2017 8:37 AM in response to VikingOSX

That answer is perfect. Thank you, VikingOSX.


I made this script and then assigned the cmd-c keyboard shortcut to this script. I tested it and it works flawlessly.


Just in case anyone else is wondering how to do that,


a. follow VikingOSX's above instructions,

b. go to Keyboard Shortcuts in System Preferences (use the search field in System Preferences if you can't find it)

c. click on "App Shortcuts"

d. click on the + button

e. select "Application" pulldown menu, choose Safari

f. type "Remove HTML from Text" in the "Menu Title" field

g. hit the cmd and c buttons in the "Keyboard Shortcut" field

h. Quit and re-open Safari. Highlight some text and hit cmd-c. It should work. I think I had to go to the Safari:Services pull-down menu once and select the "Remove HTML from Text" service while text was highlighted once in order to get it to work, but now it seems to work consistently.

copy text without links in safari

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.