我正在用Java构建一个截图程序,并且,我希望为用户提供选项,以便添加到登录项目"到目前为止,这是我尝试过的代码:
String jarPath = Core.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
Runtime.getRuntime().exec("osascript -e 'tell application \"System Events\" to make login item at end with properties {path:\""+jarPath+"\", hidden:false}'");
我知道命令是正确的,因为打印出来时会显示:
osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Users/Debuginator/Desktop/Client.jar", hidden:false}'
奇怪的是,如果我手动将此命令输入终端,它可以完美地工作。有谁知道我可能做错了什么?