我正在尝试制作一个使用Applescript生成和应用程序的应用程序,到目前为止,我已经通过使用(do shell script“ osacompile ...”)命令生成了正常运行的应用程序。现在,我只需要一个字符串即可自动更改生成的应用程序的图标,因为我希望自己的图标成为新生成的应用程序的图标,而不是默认的Applet图标。
有什么方法可以解决这个问题?
万分感谢。
埃里克
使用来自firefox的私有javascript,这会创建带有自定义图标的应用程序,唯一的问题是,每当您单击该应用程序时,它都会抛出“身份不明的作者”并且无法运行。
但这至少告诉您如何设置自定义图标。感谢@djBazzieWazzie解释上面的目录。
_createShortcutMac : function(target, name, id, icon, location) {
var desktop = dirSvc.get("Desk", Ci.nsIFile);
this._createBundle(target, name, id, icon, desktop);
}
_createBundle : function(target, name, id, icon, location) {
var contents =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" +
"<plist version=\"1.0\">\n" +
"<dict>\n" +
"<key>CFBundleExecutable</key>\n" +
"<string>" + name + "</string>\n" +
"<key>CFBundleIconFile</key>\n" +
"<string>" + icon.leafName + "</string>\n" +
"</dict>\n" +
"</plist>";
location.append(name + ".app");
if (location.exists())
location.remove(true);
location.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
location.append("Contents");
location.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
var info = location.clone();
info.append("Info.plist");
var stream = Cc['@mozilla.org/network/file-output-stream;1'].createInstance(Ci.nsIFileOutputStream);
stream.init(info, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0600, 0);
stream.write(contents, contents.length);
stream.close();
var resources = location.clone();
resources.append("Resources");
resources.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
icon.copyTo(resources, icon.leafName);
var macos = location.clone();
macos.append("MacOS");
macos.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
var cmd = "#!/bin/sh\nexec " + target.path + " -webapp ID";
var script = macos.clone();
script.append(name);
stream.init(script, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0755, 0);
stream.write(cmd, cmd.length);
stream.close();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句