Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johannnn

macrumors 68020
Original poster
Nov 20, 2009
2,351
2,709
Sweden
I am trying to set up an applescript that removes all the empty lines from my clipboard. I came up with this script

Code:
do shell script "pbpaste | sed 's/^\n//' | pbcopy"

I have tried the regex s/^\n// with a perl one-liner and it works fine.

However, every time I try to compile the applescript in the AppleScript Editor I get

Code:
do shell script "pbpaste | sed 's/^
//' | pbcopy"

The \n is removed and replaced with a blank line, and the script will not work.

How do I get this to work? :confused:

Thanks
 
The script seems to do nothing when I do \\n.

(To try, copy something with a blank line, add the script to AppleScript Editor and run it, and then paste your clipboard and see if the blank line is gone)
 
Go to preferences-->Editing and check Escape tabs and line breaks in strings
 

Attachments

  • Picture 1.png
    Picture 1.png
    52.2 KB · Views: 498
Go to preferences-->Editing and check Escape tabs and line breaks in strings
Thanks that did the trick!

Although, for some reason my clipboard is empty after running the script, makes no sense. Oh well another night at google
 
Try this :

Code:
pbpaste | sed '/^$/d' | pbcopy
 

Attachments

  • Picture 2.png
    Picture 2.png
    72.8 KB · Views: 453
  • Picture 3.png
    Picture 3.png
    26.5 KB · Views: 390
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.