4

Bluetooth を切り替える 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

終わりを告げる

4

1 に答える 1

4

"OK" "Turn Bluetooth off"である必要があります{"OK", "Turn Bluetooth off"}

また、Option-l (小文字の L) を入力しdisplay dialogて行を「継続」しない限り、ステートメントはすべて 1 行に収める必要があります。¬

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 言語ガイド

于 2013-01-22T18:38:48.527 に答える