【问题标题】:Expected end of line, etc. but found “"”预期的行尾等,但发现“””
【发布时间】:2013-06-06 00:35:17
【问题描述】:

我正在尝试制作一个可以切换蓝牙的 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

说完

【问题讨论】:

  • 是否说明错误在哪一行?
  • 不,基本的 AppleScript 编译器毫无用处。但是用户安德鲁在下面的答案中解决了我的问题。

标签: applescript


【解决方案1】:

"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

【讨论】:

  • OPTION-RETURN 也能做 ¬ - thingy
  • 我发现在最初发现答案不起作用后,退出并重新打开 Apple Script Editor 有效。
猜你喜欢
  • 1970-01-01
  • 2013-12-31
  • 2017-11-20
  • 2016-04-25
  • 1970-01-01
  • 1970-01-01
  • 2010-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多