zimbra-mirror icon indicating copy to clipboard operation
zimbra-mirror copied to clipboard

createShorcutMac throws "unidentified developer"

Open Noitidart opened this issue 10 years ago • 0 comments

I used this code here as reference to create a function to create shortcut on mac:

https://github.com/Grynn/zimbra-mirror/blob/074c1ea8a288627b845a99399eec6b2f3ce738d5/ZimbraOffline/prism/versions/0.8/macos/prism/Prism.app/Contents/Resources/modules/WebAppInstall.jsm#L193

this is my code, can copy paste to scratchpad and run.

var PR_WRONLY = 0x02;
var PR_CREATE_FILE = 0x08;
var PR_TRUNCATE = 0x20;

var shortcutService = {
    _createShortcutMac: function(target, name, id, icon, location) {
        //id argument can be anything i dont use it
        //icon is icon path
        //location is `desktop,` or `desktop,applications,` or `applications,` it tells where you want the shortcuts made

        var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);

        var locations = location.split(",");
        icon = new FileUtils.File(icon);
        if (locations.indexOf("desktop") > -1) {
            var desk = dirSvc.get("Desk", Ci.nsIFile);
            this._createBundle(target, name, id, icon, desk);
        }
        if (locations.indexOf("applications") > -1) {
            var apps = dirSvc.get("LocApp", Ci.nsIFile);
            apps.append("MY CUTS");
            if (!apps.exists())
                apps.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
            this._createBundle(target, name, id, icon, apps);
        }
        if (locations.indexOf("dock") > -1) {
            // ???
        }
    },

    _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;
        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();
    }
};

var icon_path = FileUtils.getFile('Desk', ['firefox.icns']).path;
shortcutService._createShortcutMac(FileUtils.getFile('XREExeF', []).path + ' -no-remote -P', 'my ff shortcut', null, icon_path, 'desktop,');

https://ask.mozilla.org/question/1126/shortcut-created-on-mac-but-cant-get-around-unidentified-developer-error/

but it throws this error when clicking on the desktop shortcut:

do you know how to get around this?

Noitidart avatar Sep 17 '14 08:09 Noitidart