是否可以在没有 Applescipt 帮助的情况下直接在 Java 中获得 Finde-Selection?基本上可以通过在 Java 中执行一个 osascript 来调用另一个将 Finder-selection 作为字符串传递的 applescript。谢谢。
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
** 编辑 **
我做了一个图书馆。你可以在 github 上得到它。