Question

I am trying to change the volume on my mac running OSX Mavericks. I am currently using this code:

Runtime.getRuntime().exec("/usr/bin/osascript -e 'set volume 15'");

But although I do not get any errors the volume does not change. I tried running the same command from terminal and it worked. What am I doing wrong?

Was it helpful?

Solution

Use a ProcessBuilder, and set the three parts of the command (osascript, -e and set volume 15) as separate “words” in the command. Then you'll get Java to handle the correct quoting for you rather than trying to figure it out for yourself (which is a bit hard when dealing with arguments with spaces in).

The single quotes are a feature of the interactive shell, not of osascript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top