Java 将自定义图标指定给Mac桌面元素
我正在用Swing编写一个应用程序,其中包括在桌面上为特定站点创建一个Internet快捷方式。它在Windows中工作正常。Mac允许我创建快捷方式,但不允许我将其指定为自定义图标。如何以编程方式将图标分配给Mac上的URL文件 这是我的代码:Java 将自定义图标指定给Mac桌面元素,java,macos,icons,shortcuts,filewriter,Java,Macos,Icons,Shortcuts,Filewriter,我正在用Swing编写一个应用程序,其中包括在桌面上为特定站点创建一个Internet快捷方式。它在Windows中工作正常。Mac允许我创建快捷方式,但不允许我将其指定为自定义图标。如何以编程方式将图标分配给Mac上的URL文件 这是我的代码: import java.io.*; public class MACutils { private MACutils() { } public static void createInternetShortcutOnDesk
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();
}
}
您可以创建一个扩展名为
.webloc
的文件,然后使用URL向该文件写入plist,即
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>URL</key>
<string>http://hasseg.org/setWeblocThumb/#scmRepoInfo</string>
</dict>
</plist>
统一资源定位地址
http://hasseg.org/setWeblocThumb/#scmRepoInfo
编写图标更为棘手,因为MacOSX将其存储在资源分叉中
请参阅。hi@nekno setweblocThumb对我不起作用,尽管我正在将.webloc文件添加到我的桌面,但它在终端上不断抛出“找不到要启动的文件”。另外,它应该分配链接指向的网页的图像,而不是我的自定义.icns或.png文件。我需要将此文件发送给我的客户,我真的需要有我自己的自定义图标文件。是否有其他方法可以做到这一点?。。