0

This bit of AppleScript works. If I have the System Preferences Sound panel open, and run it in the Script Editor app, it changes the volume to be at 50%.

tell application "System Events"
    tell process "System Preferences"
        set v to value of slider 0 of window 0
        log v
        set value of slider 0 of window 0 to 0.5
    end tell
end tell

This, which tries to be the same thing, fails. Anyone know how to fix it?

var se = Application("System Events");
var spp = se.processes["System Preferences"];

spp.windows[0].sliders[0].value = 0.5

var curr = spp.windows[0].sliders[0].value();
console.log("Current value: " + curr + " - " + typeof(curr));

It ends up setting it to 0. It seems I can only set the volume to 0 or 1. In reality I'm trying to script another application, but this boils down the problem.

Rob N
  • 15,024
  • 17
  • 92
  • 165
  • I know you're going to hate this, but it looks like an ugly bug. I've been trying all sorts of different things, but everything points to a spurious boolean being created in one direction. – CRGreen Feb 20 '15 at 23:44

1 Answers1

1

As I noted in my comment, I'm 90% sure this is a bug. Here's a workaround:

app = Application.currentApplication();
app.includeStandardAdditions = true;
try {
app.doShellScript('osascript -e \'tell application "System Events" to set value of slider 0 of window 0 of process "System Preferences" to 0.2\'');
} catch (error ) {
-1;
}
CRGreen
  • 3,406
  • 1
  • 14
  • 24