Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active December 18, 2015 04:59
Show Gist options
  • Save ttscoff/5729733 to your computer and use it in GitHub Desktop.
Save ttscoff/5729733 to your computer and use it in GitHub Desktop.
Dial a phone number detected in text with Skype. Part of a [PopClip Extension](https://github.com/ttscoff/popclipextensions).
#!/usr/bin/ruby
input = ENV['POPCLIP_TEXT']
# use a regex to locate all phone numbers
phone_numbers = input.scan(/(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?/)
# send the first one to Skype via AppleScript (osascript)
%x{/usr/bin/osascript -e 'set _cmd to "CALL #{phone_numbers[0].join("")}"' -e 'tell application "Skype" to send command _cmd script name "PCDIALER"'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment