본문 바로가기

macOS

전화번호(핸드폰)에 +82 국가코드 붙이는 스크립트

728x90
반응형

맥용 iMessage 에서 +82 가 붙어서 메시지가 들어오는 현상이 발생하였다.

연락처에는 +82 가 없는 차이로 누군지 보이지 않는 결과가 나타났다.

인터넷을 뒤지고 로그를 남겨보면서 최종 수정한 애플 스크립트이다.


tell application "Contacts"
    log "total person:" & (count person)
   
    repeat with anItem in every person -- 등록된 사람 단위로
        log "person phones ====> " & anItem's phones's value
       
        -- 한 사람의 전화번호 모두를 리스트로 복사한다.
        set plst to anItem's phones's value
        log "plst >>>>>> " & plst
       
        -- 전화번호 갯수를 구한다.
        set cntpnum to count plst
       
        -- 전화번호 갯수만큼 반복한다.
        repeat with n from 1 to cntpnum
           
            -- 첫번째 전화번호를 가져온다.
            set pnum to item n of plst
           
            set telid to get text 1 through 3 of pnum
            log "telid ===> " & telid
           
            if telid = "010" or telid = "011" or telid = "016" or telid = "017" or telid = "018" or telid = "019" then
                set len to length of pnum
                set pnum to "+82" & (get text 2 through len of pnum)
                log "converted phone number ====> " & pnum
               
                -- 변경된 내용을 적용한다.
                set plst's item n to pnum
            end if
           
        end repeat
       
        set i to 1
       
        repeat with anPhone in anItem's phones -- 사람의 전화번호 단위로
            -- log "before phone numbers ====> " & anPhone's value
           
            set readnum to item i of plst
            log "readnum >>>>>> " & readnum
           
            set value of anPhone to readnum
           
            set i to i + 1
           
        end repeat
       
        log "after phone numbers ====> " & anItem's phones's value
    end repeat
   
    save
   
end tell

82국가번호붙이기(1).scpt


반응형