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
.