PDA

View Full Version : \n within regex gets replaced with new line by AppleScript Editor




poobear
Jun 27, 2012, 02:50 PM
I am trying to set up an applescript that removes all the empty lines from my clipboard. I came up with this script

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

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



chown33
Jun 27, 2012, 02:58 PM
Try \\n.

poobear
Jun 27, 2012, 03:03 PM
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)

kryten2
Jun 27, 2012, 03:12 PM
Go to preferences-->Editing and check Escape tabs and line breaks in strings

poobear
Jun 27, 2012, 04:00 PM
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

kryten2
Jun 27, 2012, 04:52 PM
Try this :

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

poobear
Jun 27, 2012, 04:56 PM
Try this :

pbpaste | sed '/^$/d' | pbcopy
kryten2 I love you.

kryten2
Jun 27, 2012, 05:51 PM
Thanks :D