This package allows you to read and write Desktop Entry files.
With this package you can;
- serialize the opened Desktop Entry files to JSON.
- make changes to entry file
- overwrite the orginal file or save to another location
- preserve comments
JSON.parse(JSON.stringify(value))
is used to clone passed object.
let obj = {
"Desktop Entry": {
"comment": "inline comment",
"precedingComment": ["preceding multiline comment", "second line"],
"entries": {
"Type": { "value": "Application", "comment": "", "precedingComment": [] },
"Name": { "value": "Foo Viewer", "comment": " inline comment", "precedingComment": ["precedingComment of an entry"] },
"Exec": { "value": "fooview %F", "comment": "", "precedingComment": [] },
"Icon": { "value": "fooview", "comment": "", "precedingComment": [] }
}
}
}
let desktopEntry = new DesktopEntry(obj);
let desktopEntry = new DesktopEntry("/usr/share/applications/DesktopEntry.desktop");
console.log(JSON.stringify(desktopEntry.JSON, null, 2));
"Categories=Network;WebBrowser" => "Categories=Game"
desktopEntry.setValue("Desktop Entry", "Categories", "Game")
Adds value to entry: "Categories=Network;WebBrowser" => "Categories=Network;WebBrowser;Game"
desktopEntry.addValue("Desktop Entry", "Categories", "Game")
desktopEntry.setComment("Desktop Entry", "Exec", "Beware!!")
desktopEntry.setPrecedingComment("Desktop Entry", ["Comment preceding this entry", "Second line"])
Returns a promise
desktopEntry.save()
Returns a promise
desktopEntry.saveTo("/new/path/newfile.desktop")
Used some parts of code from node-file-parser