Question

I am looking for a text service that I can call from a plain text editor (BBedit for example) and will operate the following modification:

Before:

This is a line of text

After:

This is a line of text
----------------------

Thanks !

Was it helpful?

Solution

BBedit can execute shell commands on selected text, so adapting something like

echo 'This is a line of text' | sed -n 'p;s/./-/gp'

to make it work when called from BBedit should work.

  • sed -n runs sed without echoing its input automatically
  • p is the first command applied to the input, it just prints the input (technically the content of the pattern space)
  • s/./-/gp is the second command, it replaces all characters in the pattern space by - and prints the result

OTHER TIPS

For the benefit of future readers here is my setup. Based on @nohillside 's answer I used Automator to create a service that runs the (bash) shell script:

sed -n 'p;s/./-/gp'

That makes it easy to add a keyboard shortcut that can be accessed from text editors. Here it is:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top