Applescipt の助けを借りずに Java で Finde-Selection を直接取得することは可能ですか? 基本的には、Java で osascript を実行して、Finder 選択を文字列として渡す別の 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から入手できます。