final String[] script = {"osascript", "-e", "tell application \"System Events\"", "-e", "tell (first process whose frontmost is true) to return name of window 1", "-e", "end tell"};
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(script).getInputStream()))) {
String buffer = null;
while ((buffer = bufferedReader.readLine()) != null) {