Jump to content

Wrap text in double carets ("^^") for Roam Research highlighting


Recommended Posts

Posted (edited)

What this workflow does:

This Alfred workflow wraps whatever text is highlighted on your screen in pre-specified text strings.

 

By default, this workflow will wrap the highlighted text in double carets (i.e. "^^"), but you can very easily change what text to add right before and after your highlighted text by simply editing the code to replace the `'^^'`'s on each side of `argv` with whatever text you want (making sure that whatever text you want to add is also surrounded by quotation marks).

 

This is how the Ruby code that powers workflow looks "out of the box":

 

print ARGV.map{ |argv|'^^' + argv + '^^' }.join


If I wanted to change the workflow to wrap a piece of text—like "hello, world", for example—such that it came out "Well, hello, world!", all I would have to do is edit the code to look like this:

 

print ARGV.map{ |argv|'Well, ' + argv + '!' }.join

 

How to use this workflow:

To use this workflow, visit my GitHub page for this workflow, download the "wrap-selected-text.alfredworkflow" file, and open the file with Alfred.

 

Edited by eupraxia
Fixed formatting
Link to comment

Welcome @eupraxia,

 

As much as I’m glad to see more Workflows written in Ruby, this is more complex than it needs be. Instead of print ARGV.map{ |argv|'^^' + argv + '^^' }.join you could just print "^^#{ARGV[0]}^^"; `ARGV` will always be a one-item array in this situation, so map and join are unnecessary. But even that is too complex, you don’t need code at all! You can delete the Run Script, Connect the Hotkey directly to the Copy to Clipboard and have the delimiters there: ^^{query}^^.

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...