特定のサイトのデスクトップにインターネット ショートカットを作成するアプリケーションを Swing で作成しています。Windowsでは問題なく動作します。Mac ではショートカットを作成できますが、カスタム アイコンを割り当てることはできません。プログラムで Mac 上の URL ファイルにアイコンを割り当てるにはどうすればよいですか?
これは私のコードです:
import java.io.*;
public class MACutils {
private MACutils() {
}
public static void createInternetShortcutOnDesktop(String name,
String target, String icon) throws IOException {
String username = System.getProperty("user.home");
System.out.println(username);
String path = username + "/Desktop" + "/" + name + ".URL";
createInternetShortcut(name, path, target, icon);
}
public static void createInternetShortcut(String name, String where,
String target, String icon) throws IOException {
FileWriter fw = new FileWriter(where);
fw.write("[InternetShortcut]\n");
fw.write("URL=" + target + "\n");
if (!icon.equals("")) {
fw.write("IconFile=" + icon + "\n");
// icon has the path to my .png/.icns image
fw.write("IconIndex=0");
}
fw.flush();
fw.close();
}
}