Created
November 17, 2009 22:08
-
-
Save craSH/237315 to your computer and use it in GitHub Desktop.
AppleScript plugin for Address Book to add a Dial with Skype menu item to phone numbers. Place in ~/Library/Address Book Plug-Ins/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using terms from application "Address Book" | |
on action property | |
return "phone" | |
end action property | |
on action title for p with e | |
if label of e is equal to "Skype" then | |
return "Call Skype Name" | |
else | |
return "Dial using Skype" | |
end if | |
end action title | |
on should enable action for p with e | |
return true | |
end should enable action | |
on perform action for p with e | |
set _alphabet to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "? | |
q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "? | |
K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "+"} | |
set phone_num to the value of e | |
set phoneC to character 1 of phone_num as string | |
if phoneC is not in _alphabet then | |
set phone_num to "+1" & characters 2 thru -1 of phone_num --addplus(phone_num, _alphabet) | |
else | |
end if | |
-- Clean up the number from any extraneous characters | |
-- like blanks, '(', ')', '-' . | |
set phone_num to replace_chars(phone_num, "-", "") | |
set phone_num to replace_chars(phone_num, ".", "") | |
set phone_num to replace_chars(phone_num, "(", "") | |
set phone_num to replace_chars(phone_num, ")", "") | |
set phone_num to replace_chars(phone_num, " ", "") | |
skype_out(phone_num) | |
end perform action | |
on addplus(phone_num, _alphabet) | |
--if phone_num does not start with "+" then | |
set phone_num to "+1" & characters 2 thru -1 of phone_num | |
--end if | |
end addplus | |
end using terms from | |
on skype_out(phone_num) | |
tell application "Skype" | |
activate | |
set call_string to "callto:" & phone_num | |
get URL call_string | |
end tell | |
end skype_out | |
-- Text replace function | |
on replace_chars(this_text, search_string, replacement_string) | |
set AppleScript's text item delimiters to the search_string | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the replacement_string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment