The Shape of Everything
A website mostly about Mac stuff, written by August "Gus" Mueller
» Acorn
» Retrobatch
» Mastodon
» Micro.blog
» Instagram
» Github
» Maybe Pizza?
» Archives
» Feed
» Micro feed
January 12, 2004
(This post is from my old, old, super old site. My views have changed over the years, hopefully my writing has improved, and there is now more than a handful of folks reading my site. Enjoy.)

Monday, January 12th, 2004

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.

-- posted 1:43 pm