I'm trying to create a shortcut that launches a profile on the desktop in Linux.
I'm using this code:
Cu.import('resource://gre/modules/FileUtils.jsm'); var exe = FileUtils.getFile('XREExeF', []); var args = '-P -dev -no-remote';
var name = "mysc";
var target = exe;
var cmd = "[Desktop Entry]\n";
cmd += "Name=" + name + "\n";
cmd += "Type=Application\n";
cmd += "Comment=Web Application\n";
cmd += "Exec=" + target.path + " " + args + "\n";
//cmd += "Icon=" + icon.path + "\n";
Cu.import("resource://gre/modules/osfile.jsm")
var path = OS.Path.join(OS.Constants.Path.desktopDir, 'mysc.desktop');
Services.ww.activeWindow.alert(path)
let encoder = new TextEncoder();
let array = encoder.encode(cmd);
let promise = OS.File.writeAtomic(path, array, {tmpPath: "file.txt.tmp"});
promise.then(
function(aVal) {
Services.ww.activeWindow.alert('success aVal = ' + uneval(aVal));
},
function(aRejReas) {
Services.ww.activeWindow.alert('rejected for reason: ' + uneval(aRejReas))
}
)
How can i set chown and chmod?
I found this code https://github.com/johnshih/releases-mozilla-aurora/blob/dc29053a4b1765cf94a8562130865036c373038e/toolkit/components/osfile/osfile_unix_back.jsm#L218
UnixFile.chmod =
declareFFI("chmod", ctypes.default_abi,
/*return*/
Types.negativeone_or_nothing,
/*path*/
Types.path,
/*mode*/
Types.mode_t);
UnixFile.chown =
declareFFI("chown", ctypes.default_abi,
/*return*/
Types.negativeone_or_nothing,
/*path*/
Types.path,
/*uid*/
Types.uid_t,
/*gid*/
Types.gid_t);
Someone told me to set chown noi
and chmod +x
on the file because my path to desktop is: /home/noi/Desktop/mysc.desktop
will fix this error here:
Maybe OS.File.setPermissions
?
I tried this but it didnt work:
var promise2 = OS.File.setPermissions(path, {
unixMode: OS.Constants.libc.S_IRWXO
});
promise2.then(
function(aVal) {
console.log('promise2 success', 'aVal:', aVal);
},
function(aReason) {
console.warn('promise2 rejected', 'aReason:', aReason);
}
);