Like to create hyperlink from copied text and paste into html body such as a Gmail email.

Hello,


I would like to have a hyperlink of the URL made automatically each time I copy text from a webpage in Safari.

Then I would like the pasted text to render as a clickable link inside a message in html such as a new Gmail email message.


Searching for this feature doesn't turn up anything in the Safari extensions store.


But this is how I research.


Is there a solution?


Thank you.


Sincerely,


JWP -June 15, 2019

MacBook Pro 15", macOS 10.14

Posted on Jun 15, 2019 3:57 PM

Reply
11 replies

Jun 16, 2019 4:57 AM in response to jpeek345

There can be no automatic URL assignment of pasted plain text from the Apple clipboard, as no URL of the donor site accompanies the original copied text onto the clipboard.


If the copied text is itself a URL link, or a URL link resides within the copied text, then that hyperlink survives a copy/paste operation into Apple Mail, and probably even Gmail.

Jun 17, 2019 5:29 PM in response to jpeek345

I have an Automator Quick Action that I have tested on Mojave 10.14.5, that I believe will do what you want.


You select text on a web page, and then right-click to expose the Services menu, where you select the Quick Action name. Automator then gets this text, puts it on the clipboard, and then gets the URL of the current tab that you were on in the browser.


Then, it constructs the hyperlinked text that you selected, and puts it back on the clipboard. A dialog appears informing you that it is available to paste in Mail, where the hyperlinked text pastes, and clicking on that link sends you back to the webpage where the text originated. Right now, this works for Safari and Apple Mail, but may also work with Gmail.

Jun 28, 2019 8:10 PM in response to VikingOSX

VikingOSX,


suh-weeeet!


I haven't tried the keyboard shortcut yet but will definitely hook it up for even greater ease.


The pasted text has a nice and tight font too.




Thank you very much!


One last request if you get around to it:


Is there anyway to add citation script to the bottom of each excerpted text such as this code from Wikepedia

  • {{cite web |url=http://www.example.org/ |title=My Favorite Things, Part II |last=Doe |first=John |publisher=Open Publishing |date=April 30, 2005 |website=Encyclopedia of Things |access-date=June 27, 2019}}

Doe, John (April 30, 2005). "My Favorite Things, Part II"Encyclopedia of Things. Open Publishing. Retrieved June 27, 2019.



That would be bangin'...


Then I can attribute to the author when optional or compulsory.


Thanks Viking OSX!!


Sincerely,


JWP



Jun 21, 2019 6:04 AM in response to jpeek345

So far, only content selected in Safari enables a workable Quick Action to paste linked text into Apple Mail, and Google Mail (web). I do not have a resident Gmail application on my Mac, so haven't tested that. Here is a paste into Gmail (web):


Is this the formatting you expected? A dialog will appear when the URL linked text is ready to paste from the clipboard.


To set up the Quick Action, you do Dock : Launchpad : Other : Automator. Then:

  1. New Document : Quick Action : Choose
  2. Workflow receives current [rich text] in [Safari]. All other settings are default.
    1. From Utilities Library, drag and drop Copy to Clipboard action into the large workflow window
    2. From Utilities Library, drag and drop Run AppleScript action below the preceding action.
    3. Select all content in the Run AppleScript window, and backspace to remove.
    4. Copy/paste the following code (below) back into the Run AppleScript window. Click the hammer icon to compile.
    5. Save… I named my Quick Action: Selected Text as Mail URL.


code:

-- Convert selected text into hyperlinked text on clipboard using URL of current Safari tab or window
-- select text in a Safari browser, run this quick action, and then paste from clipboard into Mail compose window
-- reference: https://stackoverflow.com/questions/11297555/applescript-create-url-anchor-text-pass-to-clipboard-as-url-type-data
-- Tested: macOS Mojave 10.14.5 and Safari 12.1.1. Pasted URL linked text into Mail compose, and Gmail (web) compose windows
-- VikingOSX, 2019-06-20, Apple Support Communities, No warranty expressed or implied.

use scripting additions

on run {input, parameters}
	
	set theURL to ""
	tell application "Safari"
		set theURL to the URL of the current tab of the front window
	end tell
	
	set anchor_content to (the clipboard)
	set the clipboard to "<a href=\"" & theURL & "\" target=\"_blank\">" & anchor_content & "</a>"
	set theEncoding to (do shell script "pbpaste | hexdump -ve '1/1 \"%.2x\"'")
	
	run script "set the clipboard to «data HTML" & theEncoding & "»"
	
	display dialog "Paste URL encoded text from the clipboard into your Mail compose window..."
	return input
end run


When you select text in Safari, you can either right-click and choose Services -> Text as Mail URL, or access the Quick Action from the Safari : Services sub-menu. You can even assign an unused keyboard shortcut to this Quick Action in System Preferences : Keyboard : Shortcuts : Services by clicking on the far right entry for the Quick Action entry where it shows none. This will change to Add Shortcut, and clicked again, it will present an entry field for the keyboard shortcut. Press return. Now, after selecting text in Safari, you can just press the keyboard shortcut.


Firefox used to make getting the URL of the current page easy via AppleScript but no longer. So I didn't add support for Firefox, and I don't have Google Chrome installed. AppleScript will panic when it cannot find the installed application, so I couldn't add the Chrome code in the above either.


The finished Quick Action:



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Like to create hyperlink from copied text and paste into html body such as a Gmail email.

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