0

I've tried with:

ProcessBuilder pb = new ProcessBuilder("osascript script.scpt");
pb.inheritIO();
pb.directory(new File("bin"));
try {
    pb.start();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

but I always get the error "no such file or directory". I've tried also with:

Runtime.getRuntime().exec("osascript script.scpt");

but nothing happens.

I also tried using this string in both the snippets above, but nothing changed.

osascript -e 'tell application \"Safari\" to quit' 
2
  • 1
    You should use ProcessBuilder proc = new ProcessBuilder("osascript", "script.scpt"); Commented Jun 9, 2018 at 20:37
  • Dupe stackoverflow.com/questions/11593849/… and stackoverflow.com/questions/6856028/… . Note you are not running a bash command; ProcessBuilder or Runtime.exec runs a program in a fashion similar in some respects to a shell (including bash) command but not identical. Commented Jun 9, 2018 at 23:23

1 Answer 1

0

I was able to fix the issue by using this

ProcessBuilder proc = new ProcessBuilder("osascript", "script.scpt");

This is because there's no tokenisation: the command to run is assumed to have already been tokenised.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.