It seems that sometimes when I'm trying to copy some code from safari, and I paste it into CodeWarrior, or XCode, or whatever- some strange chars get put in as well and the compiler doesn't like them.
I finally got annoyed enough with it that I tracked it down, and it turns out it's the char '\xCA' which looks like it's just another type of space. So I wrote a quick little python script to take care of it. I called it "desafari.py" and when called from the shell, it looks at the current clipboard, and replaces the troublesome character with a normal, compiler friendly space.
import string
from Carbon import Scrap
try:
data = Scrap.GetCurrentScrap().GetScrapFlavorData("utxt")
except:
try:
data = Scrap.GetCurrentScrap().GetScrapFlavorData("TEXT")
except:
# silently fail
pass
if data is not None:
# replace safari's funny, programmer un-friendly space
# with a regular space
data = string.replace(data, "\xCA", " ")
Scrap.ClearCurrentScrap()
Scrap.GetCurrentScrap().PutScrapFlavor('TEXT', 0, data)
else:
print "No text for me"
Happy horray. I'm sure there's something wrong with it- please tell me what it is in the comments.comments (2) # posted 1:43 pm (uct-6)