Skip to content

ilgarmehmetali/freedesktop-desktop-entry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Freedesktop Destop Entry

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
constructor

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");
get JSON
console.log(JSON.stringify(desktopEntry.JSON, null, 2));
setValue

"Categories=Network;WebBrowser" => "Categories=Game"

desktopEntry.setValue("Desktop Entry", "Categories", "Game")
addValue

Adds value to entry: "Categories=Network;WebBrowser" => "Categories=Network;WebBrowser;Game"

desktopEntry.addValue("Desktop Entry", "Categories", "Game")
setComment
desktopEntry.setComment("Desktop Entry", "Exec", "Beware!!")
setPrecedingComment
desktopEntry.setPrecedingComment("Desktop Entry", ["Comment preceding this entry", "Second line"])
save

Returns a promise

desktopEntry.save()
saveTo

Returns a promise

desktopEntry.saveTo("/new/path/newfile.desktop")

Used some parts of code from node-file-parser

About

Node module to handle freedesktop desktop entry files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published