forked from cerebroapp/cerebro-osx-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
50 lines (41 loc) · 1.38 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var fs = require('fs');
var stringSearcher = require('string-search');
var path="/usr/share/applications";
var apps = new Array();
//fs.readdir(path, (err, files) => {
//files.forEach(file => {
//console.log("\n\n"+file+"\n\n");
//if(fs.lstatSync(path+"/"+file).isFile())
fs.readFile("/usr/share/applications/cinnamon-control-center.desktop",{encoding: "utf8"}, function read(err, data) {
if (err) {
console.log(err)
}
content = data;
var nameapp="";
stringSearcher.find(content, '^Name').then(function(resultArr) {
//resultArr => [ {line: 1, text: 'This is the string to search text in'} ]
nameapp=resultArr[0].text.replace("Name=","");
console.log(nameapp);
if(!apps[nameapp])
apps[nameapp]="";
});
stringSearcher.find(content, '^Exec')
.then(function(resultArr) {
//resultArr => [ {line: 1, text: 'This is the string to search text in'} ]
if(resultArr[0].text){
var s=resultArr[0].text.replace("Exec=","");
if(s.indexOf('%')>0)
s=s.substring(0, s.indexOf('%'));
apps[nameapp]=s;
}
console.log(apps);
//console.log(apps);
});
// Invoke the next step here however you like
//console.log(content); // Put all of the code here (not the best solution)
// Or put the next step in a function and invoke it
});
// console.log(file);
// });
console.log(apps);
//})