본문 바로가기
정보기술/Mac

Mac 주소록에서 바로 전화 거는 방법 - Skype & X-Lite 4 이용

by fermi 2011. 10. 26.
참고: Peter Kim 블로그 http://goo.gl/vQp88

Apple script 를 이용한 주소록 plug in 을 작성하면 Mac의 주소록에서 바로 전화를 걸 수 있다. Skype 또는 X-Lite 와 같은 VoIP를 즐겨쓴다면 매우 유용하다.

방법: ~/Library/Address Book Plug-Ins/ 에 script를 저장한다.


1. Skype calls from Address book

문제점: ~/Library/Address Book Plug-Ins 에 기본으로 설치되어 있는 Skype dialer 는 최신버전의 Skype 5.3.59 에서 작동하지 않는다.

아래 제공되는 Skype calls Apple script 를 다운받아 설치하면 작동한다.

http://faqintosh.com/risorse/en/othutil/addrbook/skype/

한가지 주의할 점은 Apple script를 열어서 +39로 적혀 있는 국가번호를 자신의 환경에 맞게 변경해야 한다. (+82로 변경)

2. X-Lite 4 phone calls from Address book

문제점: 구 버전의 X-Lite 에서 작동하는 Apple script 들이 X-Lite 4 에서는 작동하지 않는다. Xtendial 이라는 이벤트를 X-Lite 4 에서 더이상 지원하지 않는 것으로 보인다.

이를 해결하기 위해서는 임시 방편으로 System Events 인 Keystroke 를 이용하여 직접 X-Lite 4 에 전화번호를 입력하고 전화를 걸게 하였다.

아래 제공되는 X-Lite phone calls Apple script 를 다운받아 Xtendial 이벤트를 Keystroke로 수정한다.

http://faqintosh.com/risorse/en/othutil/addrbook/xlite/

한가지 주의할 점은 X-Lite 에서 사용하는 SIP 환경에 따라 prefix 를 변경해주어야 한다는 점이다. 본인의 경우는 국가 코드는 +82로, 전화 걸때 사용하는 prefix 는 +82 를 0 로 변경해주는 기능을 추가하였다. (아래 코드 참조)

수정한 내역은 다음과 같다.
- Xtendial 이벤트를 System Event 인 Keystroke 로 변경
- X-Lite 4 가 실행중인지 확인하는 과정 추가
- X-Lite 4 윈도우가 최소화 되어 있을때 복원하는 과정 추가
- 국가코드 +82 로 변경
- 국내전화 전용의 SIP 를 위하여 전화번호의 국가코드를 제거하고 0 을 앞에 붙이는 과정을 추가 (ex: +82-11-300-0000 을 011-300-0000 으로 변경)

알려진 문제점
- X-Lite 4 윈도우가 최소화가 아니라 아예 닫혀 있을때에는 복원이 되지만 윈도우의 focus 가 활성화되지 않는다.
- X-Lite 4 의 키보드 입력 focus 가 엉뚱한 위치에 있을때는 작동하지 않는다.


변경: X-Lite 의 버전이 5.x 로 업데이트 되면서 Application name 이 X-Lite 4 에서 X-Lite 로 변경됨에 따라 스크립트 내의 모든 "X-Lite 4" 스트링을 "X-Lite" 로 변경

using terms from application "Address Book"
   
    on action property
        return "phone"
    end action property
   
    on action title for p with v
        return "Dial with X-Lite"
    end action title
   
    on should enable action for p with v
        return true
    end should enable action
   
    on perform action for p with v
        set phnum to my filternumber(value of v)
        display dialog "Are you sure you want to call to " & phnum & " with X-Lite?" with icon caution
        if appIsRunning("X-Lite") then
        else
            tell application "X-Lite"
                activate
            end tell
            delay 6
        end if
        tell application "X-Lite"
            activate
            tell application "System Events"
                tell process "X-Lite"
                    tell menu bar 1
                        tell menu bar item "Window"
                            tell menu "Window"
                                click menu item "X-Lite"
                            end tell
                        end tell
                    end tell
                    keystroke phnum
                    keystroke return
                end tell
            end tell
        end tell
    end perform action
   
end using terms from

on filternumber(n)
    set internationalPrefix to my getccode()
    set intPrefLen to (the number of characters of internationalPrefix) + 1
    set risp to my cleannumber(n)
    if risp starts with internationalPrefix then ¬
        return "0" & (characters intPrefLen thru -1 of risp) as text
    return (risp as text)
end filternumber

on cleannumber(n)
    set validChars to "+0123456789"
    set valids to every character of validChars
    set orig to every character of n
    set risp to ""
    repeat with c in orig
        if c is in valids then set risp to risp & c
    end repeat
    return (risp as text)
end cleannumber

on getccode()
    set prefs to "com.faqintosh.AddressBookScripts"
    set prefkey to " defaultInternationalPrefix "
    do shell script "defaults write " & prefs & " XLitePlugInVersion 1.1"
    try
        set ccode to do shell script "defaults read " & prefs & prefkey
    on error
        set ccode to ""
    end try
    if ccode is "" then
        tell me to activate
        set ccode to the text returned of ¬
            (display dialog "Please initialize this script by providing your default country prefix, that will be stripped when calling:" default answer "+82" with icon note)
        set ccode to my cleannumber(ccode)
        if ccode is "" then return ""
        do shell script "defaults write " & prefs & prefkey & ccode
    end if
    return (ccode as text)
end getccode

on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning