Until now, I’ve been using the following Applescript (dragged into the XOJO project window) to turn on Bluetooth.
tell application "System Events" to tell process "SystemUIServer"
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
click bt
tell (first menu item whose title is "Turn Bluetooth On") of menu of bt
click
click menu item "Turn Bluetooth On"
end tell
end tell
It works fine, but I’d like to change it to run from a shell using the following
osascript -e 'my_Applescript_source_code'
single line command format. From what I’ve seen on Applescripting sites, if I replace the line endings in the original script with ‘¬’ (option-lowercase-L) it’s supposed to work. The resulting shell code is:
osascript -e 'tell application "System Events" to tell process "SystemUIServer"¬ set bt to (first menu bar item whose description is "bluetooth") of menu bar 1¬ click bt¬ tell (first menu item whose title is "Turn Bluetooth Off") of menu of bt¬ click¬ click menu item "Turn Bluetooth Off"¬ end tell¬end tell¬'
However, when I try it, I get this result returned from the shell:
67:296: syntax error: Expected end of line but found unknown token. (-2741)
BTW, I think I’ve properly escaped the double quotes as follows:
Dim theShellCode As String = "osascript -e 'tell application ""System Events"" to tell process ""SystemUIServer""¬ set bt to (first menu bar item whose description is ""bluetooth"") of menu bar 1¬ click bt¬ tell (first menu item whose title is ""Turn Bluetooth Off"") of menu of bt¬ click¬ click menu item ""Turn Bluetooth Off""¬ end tell¬end tell¬'"+EndOfLine
Does anyone have any ideas why this doesn’t work?
I’ve been able to run other applescripts using osascript -e in a shell, but they are all single line scripts.