在Mac上使用FaceTime通过iPhone拨号

tags: macOS, AppleScript, FaceTime, Handsoff

-- 首先、你得开启Mac和iPhone的handsoff功能
-- 其次、你可能懒得像我一样喜欢使用快捷键直接快速拨号
-- 最后、脚本如下:

-- 数字格式化剪切板,就是说一般而言对于要拨的号码你直接复制就好。
set myNumber to textFilter(get the clipboard, "0123456789")
set userCanceled to false

-- 调用对话框,安全起见你有300秒来考虑手动输入带拨叫号码或者修改剪切板里面的号码。
tell application "System Events"
    try
        set dialogResult to display dialog "Dail Phone Number" with title "Dail Phone Number via my iPhone " buttons {"Cancel", "Go"} default button "Go" cancel button "Cancel" giving up after 300 default answer myNumber
    on error number -128
        set userCanceled to true
    end try
    
    if userCanceled then
        display dialog "User Canceled."
    else if gave up of dialogResult then
        display dialog "User timed out."
    else if button returned of dialogResult is "Go" then
        set text_returned to text returned of dialogResult
    end if
end tell

-- 这里就是拨号啦。
tell application "System Events"
    -- 这里的+86表示你要拨的号是手机或者座机,对于10086或者95566之类的服务型号码是不行滴。
    open location "tel://+86" & (text_returned) & "?audio=yes"
    -- 自动点击‘‘拨号’’
    repeat while not (button "Call" of window 1 of application process "FaceTime" exists)
        delay 0.75
    end repeat
    click button "Call" of window 1 of application process "FaceTime"
end tell

on textFilter(thisText, allowedCharString)
    set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {""}}
    set the parsedList to every text item of thisText
    set newList to {}
    repeat with oneChar in parsedList
        set oneChar to contents of oneChar
        if oneChar is in allowedCharString then copy oneChar to end of newList
    end repeat
    set the newText to the newList as string
    set AppleScript's text item delimiters to oldDelims
    return newText
end textFilter

你可能感兴趣的:(在Mac上使用FaceTime通过iPhone拨号)