预计行尾等,但发现“”“

时间:2013-01-22 18:31:57

标签: applescript

我正在尝试制作一个可以切换蓝牙的AppleScript,但我似乎无法解决以下错误:

Expected end of line, etc. but found “"”.

这是我的代码:

tell application "System Preferences"
reveal pane id "com.apple.preferences.Bluetooth"
tell application "System Events" to tell process "System Preferences"
    set bluetooth to checkbox "On" of window 1
    set bluetoothBool to value of checkbox "On" of window 1 as boolean
    tell bluetooth
        if bluetoothBool = false then
            click bluetooth
            display dialog "Bluetooth on" with title "Bluetooth"
                buttons "OK" "Turn Bluetooth off"
                default button "OK"
        else if bluetoothBool = true then
            click bluetooth
            display dialog "Bluetooth off" with title "Bluetooth"
                buttons "OK" "Turn Bluetooth on"
                default button "OK"
        end if
    end tell
end tell
quit

告诉

1 个答案:

答案 0 :(得分:4)

"OK" "Turn Bluetooth off"需要{"OK", "Turn Bluetooth off"}

此外,display dialog语句需要全部放在一行,除非您通过键入Option-l(小写L)来“继续”一行¬

tell application "System Preferences"
    reveal pane id "com.apple.preferences.Bluetooth"
    tell application "System Events" to tell process "System Preferences"
        set bluetooth to checkbox "On" of window 1
        set bluetoothBool to value of checkbox "On" of window 1 as boolean
        tell bluetooth
            if bluetoothBool = false then
                click bluetooth
                display dialog "Bluetooth on" with title ¬
                    "Bluetooth" buttons {"OK", "Turn Bluetooth off"} ¬
                    default button "OK"
            else if bluetoothBool = true then
                click bluetooth
                display dialog "Bluetooth off" with title ¬
                    "Bluetooth" buttons {"OK", "Turn Bluetooth on"} ¬
                    default button "OK"
            end if
        end tell
    end tell
    quit
end tell

来源:AppleScript Language Guide