Use TextExpander to format numbers with a thousands separator
I often use LaunchBar’s calculator to do calculations, and I often need to paste the result into an email or document. If the number is greater than 1,000, I have to add commas manually. In other words, LaunchBar’s calculator spits out something like 43897909, and I have to make it 43,897,909. Not a big deal for most people, I guess, but I have to do it over and over again for certain work.
I wondered if TextExpander could put the commas in there for me. Fortunately it can.
Aside: Yes, this is another TextExpander post. Sorry. It’s actually Brett Terpstra’s fault. His shell script tricks are like a song I just can’t get out of my head. But hey, if it keeps Lady Gaga out. . .
Anyway. . . I made a slight modification to one of Brett’s shell scripts using some code I found.
Here’s what it looks like:
#!/usr/bin/env ruby -wKU
# get the clipboard using pbpaste
clip = %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}
# print it out comma separated
print clip.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
Just paste that piece of elegant code into TextExpander:
I set up a snippet (.fc) to trigger it. Now, when I do some math in LaunchBar, I can press Cmd-C to copy the answer to my clipboard, then type .fc wherever I want to put the answer with the commas already inserted. Works great, and saves me a ton of time.