jochi Posted June 18, 2013 Share Posted June 18, 2013 (edited) I want to create a workflow that will take selected text in a document, add line numbers to it, and replace the selected text in the document. I created a workflow to be initiated by a hotkey when I have text selected but it doesn't work. I think that's mostly because I'm not much of a programmer and don't know how to work this thing very well. Download the workflow I created here. Any suggestions for how to make this work would be appreciated... Edited June 19, 2013 by jochi Link to comment
vitor Posted June 19, 2013 Share Posted June 19, 2013 $1 is to be used on the shell; inside an Alfred workflow, you should be working with query (you have that instruction on the Run Script window).You should already have a nl utility installed, which is exactly for that. This code #!/bin/bash echo "{query}" | nl should do what you want.Run man nl inside the terminal to see more options (you might want to take a look specifically at the -n formatting alternatives). Link to comment
jochi Posted June 19, 2013 Author Share Posted June 19, 2013 (edited) Thanks, that helped a lot! nl didn't give me the formatting I wanted so I found an awk command that did. One thing that seems like it might be a but is the workflow is leaving escaped spaces "\" in the output. Here is the finished workflow. Edited June 19, 2013 by jochi Link to comment
vitor Posted June 19, 2013 Share Posted June 19, 2013 One thing that seems like it might be a but is the workflow is leaving escaped spaces "\" in the output. You’re telling it to (again, look around the windows Alfred shows, they try to give you instructions for each function). The awk way seems to work fine, but for reference, here’s something you could do using nl, to get the formatting you want echo "{query}" | nl | perl -pe 's/\t/. /' That’ll take the first tab character (the one that separates the number and the text) of each line, and output a period and space instead. On another note, when updating the workflow, you should update the link on the first post (stops people from having to read the whole thread to get the latest version). Link to comment
jochi Posted June 19, 2013 Author Share Posted June 19, 2013 Ha ha, well aren't I proving myself to be clueless. Thanks for the perl.. way easier to understand and see how to modify this for other purposes. Updating all links as you suggested. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now