I need a Javascript method to get me the full path of any application installed on MacOS based on the app name.
I tried using the Javascript method – mdfind – but it’s execution is asynchronous, and I am not getting the path at the point where I need it.
Here is how I used it,
var fullAppPath = "";
var mdfind = require('mdfind');
var res = mdfind({query:'kind:app', attributes: ['kMDItemDisplayName']});
res.output.on('data', function(data){
var foundApps = data.kMDItemDisplayName === appName; // eg. appName = "Adobe Acrobat"
if (foundApps) {
console.log("FOUND!!");
fullAppPath = data.kMDItemPath;
console.log(data.kMDItemPath);
}
});
How can I use the above or any similar method in a synchronous way, so that I get the results, and then move forward?