Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- #Originally posted at http://n8henrie.com/2013/01/quicksilver-action-to-format-phone-numbers
- #Corresponding AppleScript for integration with Quicksilver at http://pastebin.com/hKH9hyxn
- # Uncomment the growlnotify lines if you've installed growlnotify (highly recommended, get it at http://growl.info/extras.php#growlnotify ).
- #The "cat" here reads the input from the "echo " in the AppleScript action used by Quicksilver.
- theNumber=$(cat);
- #theNumber="0293209fjps9djf9s8dfu982392839ufsd89fu"; #comment the cat line and uncomment this for testing.
- #Get rid of all non-digit characters
- numberTrimmed=$(echo $theNumber | tr -cd "0123456789");
- #If it's got 7 or 10 digits left, go with that.
- if [[ ${#numberTrimmed} = 7 || ${#numberTrimmed} = 10 ]]
- then
- echo -n $numberTrimmed | pbcopy;
- echo $(pbpaste);
- # /usr/local/bin/growlnotify "n8henrie.com" -m "The phone number should be on your clipboard."
- #If it's got 11 digits (like the preceding 1), take the last 10.
- elif [[ ${#numberTrimmed} = 11 ]]
- then echo -n $(echo -n $numberTrimmed | rev | cut -c 1-10 | rev) | pbcopy;
- echo $(pbpaste);
- # /usr/local/bin/growlnotify "n8henrie.com" -m "The phone number should be on your clipboard."
- #Something went wrong.
- else
- 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?"
- #/usr/local/bin/growlnotify "n8henrie.com" -m "$growlMessage"
- echo $growlMessage
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement