Jump to content

Recommended Posts

I'm trying to create a workflow to transform some text into a hyperlink and automatically paste it.

 

I've copied some text to the clipboard that contains the bits that I need to form the URL.

I have a script to create the URL and I can pass it to the Copy to Clipboard Output.

But it's still just the URL text.

 
 

 

I can modify the script to hack the URL into an RTF snippet.

If I push the snippet on the clipboard in the script, I can paste it as a hyperlink, so I know it works.

 

But, if I just pass the RTF data as text to Copy to Clipboard it doesn't paste as a hyperlink (just the RTF code as text).

 

Anybody know if I'm approaching this wrong or if there's a way to programmatically create a hyperlink and automatically paste it to the front most app?

Link to comment

I'm trying to create a workflow to transform some text into a hyperlink and automatically paste it.

 

I've copied some text to the clipboard that contains the bits that I need to form the URL.

I have a script to create the URL and I can pass it to the Copy to Clipboard Output.

But it's still just the URL text.

 
 

 

I can modify the script to hack the URL into an RTF snippet.

If I push the snippet on the clipboard in the script, I can paste it as a hyperlink, so I know it works.

 

But, if I just pass the RTF data as text to Copy to Clipboard it doesn't paste as a hyperlink (just the RTF code as text).

 

Anybody know if I'm approaching this wrong or if there's a way to programmatically create a hyperlink and automatically paste it to the front most app?

 

Alfred's paste works as a plain text paste only. How to programmatically do this otherwise, I'm not sure unless you use AppleScript to manipulate the clipboard and paste that way, skipping Alfred's action for copying to clipboard and pasting..

 

I've never tried this so I'm not sure if it would work but seems like the best bet

Link to comment

Honestly, it will completely depend upon the app that you are pasting into. Some apps will automatically "sense" that the text is or contains a hyperlink and make it active (i.e. clickable). Others simply don't. Some allow you to specify that some text has a hyperlink. Its a crap shoot.

As some examples, paste a plain text hyperlink into TextEdit. It will become active. Paste the same plain text hyperlink into Evernote. Nothing will happen, tho you can make it a link. Then try pasting it into a plain text editor like Sublime Text; nothing happens.

So, tl;dr: you need to understand how exactly the app(s) you want to paste the hyperlink into work with hyperlinks. This will make your task at least much more understandable.

Link to comment

I ended up changing the starting point of the workflow.

 

Now, I'll invoke the workflow which will essentially populate the hyperlink on the clipboard.

Then I'll use <command>-v wherever I want to past the hyperlink.

 

Here's the relevant python code for these actions.

//pass in an anchor <a href="protocol://url/to/thing">Name</a>
def transformToRTF(html):
  p = subprocess.Popen(['textutil','-format','html','-convert','rtf','-stdin','-stdout'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  p.stdin.write(html)
  p.stdin.close()
  retcode = p.wait()
  data = p.stdout.read()
  return data

//use various options with pbpaste to get different types of data
def getClipboardData():
 p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE)
 retcode = p.wait()
 data = p.stdout.read()
 return data

//use various options with pbcopy to set the type of data on the clipboard
def setClipboardData(data):
 p = subprocess.Popen(['pbcopy','Prefer','rtf'], stdin=subprocess.PIPE)
 p.stdin.write(data)
 p.stdin.close()
 retcode = p.wait()
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...