Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to generate a report by using a Ruby script to parse an XML document. I'm pulling link text and the actual URL and I'd like to be able to format those in a way that I could simply copy/paste the results into Pages/Numbers and have the hyperlink with correct link text immediately set. Is there a way to do this?

share|improve this question

2 Answers 2

echo -En '<a href="http://t.co">tco</a><br><a href="http://g.co">gco</a>' | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf

The output will always include styles. For some reason pbcopy -Prefer rtf doesn't include a plain text version on the clipboard so you won't be able to paste anything in plain text views.

share|improve this answer

If you want to copy / paste a link with a descriptive text different from the URL into Pages, the OS X pasteboard needs to contain an URL object (not plain text or HTML). In Ruby, you can create such a URL pasteboard object using the pasteboard gem (gem install pasteboard) and the following code:

require 'pasteboard'
pasteboard = Pasteboard.new
pasteboard.put_url '<link URL>', '<link text>'

See the gem documentation, where I lifted this example wholesale.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.