Advertisement
n8henrie

fixPhoneNumbers.sh

Jan 28th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/bash -e
  2.  
  3. #Originally posted at http://n8henrie.com/2013/01/quicksilver-action-to-format-phone-numbers
  4. #Corresponding AppleScript for integration with Quicksilver at http://pastebin.com/hKH9hyxn
  5.  
  6. # Uncomment the growlnotify lines if you've installed growlnotify (highly recommended, get it at http://growl.info/extras.php#growlnotify ).
  7.  
  8. #The "cat" here reads the input from the "echo " in the AppleScript action used by Quicksilver.
  9. theNumber=$(cat);
  10. #theNumber="0293209fjps9djf9s8dfu982392839ufsd89fu"; #comment the cat line and uncomment this for testing.
  11.  
  12. #Get rid of all non-digit characters
  13. numberTrimmed=$(echo $theNumber | tr -cd "0123456789");
  14.  
  15. #If it's got 7 or 10 digits left, go with that.
  16. if [[ ${#numberTrimmed} = 7 || ${#numberTrimmed} = 10 ]]
  17. then
  18. echo -n $numberTrimmed | pbcopy;
  19. echo $(pbpaste);
  20. # /usr/local/bin/growlnotify "n8henrie.com" -m "The phone number should be on your clipboard."
  21.  
  22. #If it's got 11 digits (like the preceding 1), take the last 10.
  23. elif [[ ${#numberTrimmed} = 11 ]]
  24. then echo -n $(echo -n $numberTrimmed | rev | cut -c 1-10 | rev) | pbcopy;
  25. echo $(pbpaste);
  26. # /usr/local/bin/growlnotify "n8henrie.com" -m "The phone number should be on your clipboard."
  27.  
  28. #Something went wrong.
  29. else
  30. growlMessage="I think something went wrong with fixPhoneNumbers.sh."$'\n\n'"Are you sure the string you sent it has either 7, 9, or 10 digits?"
  31. #/usr/local/bin/growlnotify "n8henrie.com" -m "$growlMessage"
  32. echo $growlMessage
  33. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement