是否可以在没有Applescipt帮助的情况下直接在Java中获取Finde-Selection?基本上可以通过在 Java 中执行 osascript 来调用另一个 applescript,将 Finder 选择作为字符串传递。谢谢。
import java.io.*;
public class FinderSelection {
public static void main(String [] args) throws IOException {
String[] cmd = { "osascript", "-e", "run script \"FinderSelection.scpt\" as POSIX file" };
InputStream is = Runtime.getRuntime().exec(cmd).getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader buff = new BufferedReader (isr);
String line;
while((line = buff.readLine()) != null)
System.out.println(line);
}
}
FinderSelection.scpt
tell application "Finder"
set theSelection to selection
set item1 to POSIX path of (item 1 of the theSelection as alias) as string
end tell
** 编辑 **
我建了一个图书馆。即可获取here on github .
最佳答案
您可以通过摆脱外部 applescript 文件并使用此行来简化代码...
String[] cmd = { "osascript", "-e", "tell application \"Finder\" to return POSIX path of ((item 1 of (get selection)) as text)" };
关于java - 直接在 Java 中获取 Finder 选择,无需任何 Applescript 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18274077/