I know I can add a url and have that text automatically turned into a link, but how do I select text and turn that text into a link to a URL I specify?
I would really like to see this feature implemented too.
I did finally figure out that you can paste in a URL, then select it and change the dispayed text to be something different, which gives you the same results in a roundabout way. It would still be nice to be able to select text and turn it into a link.
Great idea and it should have the keyboard shortcut Cmd-K which is used by TextEdit, Mail, among others.
Me too was facing the same issue. Impressed with your answer. Thanks
@philipt18 said
you can paste in a URL, then select it and change the dispayed text to be something different
Just fyi ā this would be quick work with Keyboard Maestro, or any macro program.
That said, it should be built-in to OO, imho. Afaik, Apple has made this link-making available platform-wide.
Just fyi ā this would be quick work with Keyboard Maestro, or any macro program.
Tho ā perhaps I am missing something ā it doesnāt look as if the scripting API gives access to the text selection ?
(It appears to expose only row selection, which is not really what you need, but I suppose you could still use the clipboard and textutil to build and paste an RTF encoded link)
Perhaps quick ā quick-ishā¦ ?
(Not hard to see the appeal of widget-free Markdown at these moments ā¦ )
In the meanwhile, typing the url first, and then ctrl-clicking to choose Edit Link and get this:
does seem workable ā¦
PS to speed the work up a bit, in case anyone does try that with something like Keyboard Maestro, an AppleScript incantation for building the RTF might look something like:
if (strURL is not "") and (strTitle is not "") then
set strHTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & strURL & "\">" & strTitle & "</a></font>")
do shell script "echo " & strHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
end if
Keyboard Maestro and AppleScript are different programs. They work differently. Check out Keyboard Maestro ā itās a superb and in many ways exemplary program (just a satisfied user).
Here is a thread I turned up with, imho, helpful information for scripting (I donāt use AppleScript, only due to ignorance).
Here is a quickly-written Keyboard Maestro macro. It copies the selected text (in OO), pastes it into a TextEdit RTF file, adds the previous System Clipboard as a link, copies the newly created link, and pastes it OO. I used TextEdit in order to get to the āEdit ā¹ Linkā command (which OO doesnāt give us access to). Iām sure someone skilled could improve it. As is, it works.
Looks good ā I guess you could also bypass TextEdit, if you wanted to.
There is a draft of a āK at
which:
- Copies the text selected in OO4
- Prompts for a url
- Pastes back as a rich text hyperlink
Thanks for this. I did check it out on the KM site as well.
I would probably have by-passed TextEdit if I knew AppleScript š .
The suggestions the work-arounds by the responders (as well as their programming insights about how OF works) is downright impressive so kudos to all of you! To a non-programmer non-tinkerer who simply wants a streamlined experience with common key commands and shortcuts consistent across Appleās OS, these suggestions are work-arounds which would not be necessary if the good folks at the Omni Group could add the Cmd-K convention referenced by several responders. Hereās to hoping they are monitoring these forums. Cheers everyone.
I so love Omni that I hesitate to say anything, but Iām sincerely surprised at the round-about way necessary to create links. As many have noted, most apps I use allow Command-K. Is this not a standard, Apple way to do things? Is it standard, but thereās a problem implementing it with Omniās code (perhaps a carryover from NeXT code)? Iām more than a bit surprised that OO5 still does it this way.
I hope this issue is āfixedāā¦and Iām certainly open to learning why the current method is ābetterā or āmore powerfulā or āmore elegant.ā
Here is an applescript snippet that will change the text of the selected row into a link based on the clipboardās contents. Excessive apostrophe alert is in effect.
tell application "OmniOutliner"
tell selected row of document 1
set topic cell's text's style's attribute "link"'s value to the clipboard
end tell
end tell
Helpful that everyone submitted scripts and workarounds, but very surprising that this is not part of the text editor.
Even from AppleScript I wasnāt able to find a way to add a hyperlink to just the selected text, rather than the entire rowās text ā because I couldnāt get the selected text from AppleScript.
I could almost certainly do it by copying the selected text and modifying the clipboard to add a link with AppleScriptObjC, or even making a service to do it, but this seems like a lot of work for something thatās implemented in TextEdit and as @ibuys mentions, should probably be part of an 18 year old product!
I ended up making a slightly longer version of the script that prompts for the link destination, using the clipboard as the default:
tell application "OmniOutliner"
local _link, _result
set _link to ""
try
set _link to (the clipboard as string)
end try
set _result to (display dialog Ā¬
"Link selected rowās text to destination:" default answer _link Ā¬
buttons {"Cancel", "Link"} default button 2)
set _link to _result's text returned
tell selected row of document 1
set topic cell's text's style's attribute "link"'s value to _link
end tell
end tell
And a corresponding script to remove links from the selected rows (useful when copying from OmniFocus into OmniOutliner to clear all the omnifocus:// links):
tell application "OmniOutliner"
tell selected row of document 1
clear topic cell's text's style's attribute "link"
end tell
end tell
I havenāt found a way to accomplish this with selected text but with a more explicit reference, you can en-link a segment of a topic. (Just made that word up :)
set word's style's attribute "link"'s value of words 1 thru 2 of topic of child 1 of document 1 to the clipboard
It does mean that you have to figure out how to point to the text you wish to add the link to. That can be a pain. You should also be able to work with characters rather than words, etcā¦. Perhaps if you could properly convert the reference to the selected text to something more explicit, then you could turn this into a service and give it a keyboard shortcut. Maybe after I sleep for a while. I do hope itās possible.
As an aside, I find that a lot of apps have issues when working with the selected text. And as a further aside, I find TextEdit to be worse than any app that implements Applescript. Iāve spent (or wasted) untold hours slamming my head against those rocks.