Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8henrie/5182317 to your computer and use it in GitHub Desktop.
Save n8henrie/5182317 to your computer and use it in GitHub Desktop.
--Originally posted at http://n8henrie.com/2013/01/quicksilver-action-to-format-phone-numbers
--Corresponding bash script at http://pastebin.com/Dje7s4A7
property pathToShellScript : "/Users/.../fixPhoneNumbers.sh"
using terms from application "Quicksilver"
on process text str
set result to do shell script "echo \"" & str & "\" | " & quoted form of pathToShellScript
return result
end process text
end using terms from
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment