Java 程式端可以呼叫終端機來執行 apple script
靠的是 runtime.exec(args); 這行,來執行 args 的參數們
而實際執行的指令是
osascript -e 'display notification "Take a break" with title "Time up!!!" sound name ""' //可直接在終端機執行
我是放在 timer 倒數完結後(timeOut Override method),引發一個系統通知:
Runtime runtime = Runtime.getRuntime(); String[] args = { "osascript", "-e", "display notification \"Take a break\" with title \"Time's Up!!!\" sound name \"\"" }; try { Process process = runtime.exec(args); } catch (IOException ioError) { ioError.printStackTrace(); }
references:
https://alvinalexander.com/blog/post/java/how-run-execute-applescript-java-mac