14

I am wondering if there is a way to add a folder to Favorites using Node?

I've found this issue, but the solution does not work anymore.

Basically the file that I'm interested in is located in:

/Users/USER_NAME/Library/Application\ Support/com.apple.sharedfilelist

The thing is I do not know how to modify it...

mdmb
  • 4,833
  • 7
  • 42
  • 90
  • Found this thread https://www.jamf.com/jamf-nation/discussions/20218/the-slftool-thread#responseChild160825 . You could try creating a script as specified here, and then execute the script from node js. Not completely sure if this would help you. – dRoyson Sep 23 '18 at 07:08
  • I’ve already read it. Not helpful really as I do not know how to run those scripts using NodeJS – mdmb Sep 23 '18 at 18:10
  • You could execute the command using `require('child_process').exec`. If the script does not need installing additional Python libraries on the Mac, then it should work fine. – dRoyson Sep 24 '18 at 10:05

3 Answers3

2

You can use try os module. Very easy to use. Here is an example:

const home = require("os").homedir(); // This will get your OS based Home directory
const dirToSave = `${home}/Desktop/output.csv`; // Now you can add file or folder to any tree directory of home directory.
fs.writeFile(`${dirToSave}`, {csvData}, function(err, stat) {
   if (err) throw err;
   console.log("file saved");
});
Naimur Rahman
  • 697
  • 4
  • 15
0

There is a file that you need to edit

You can edit the sidebar on Mac using the com.apple.sidebarlists.plist preference file. The items will be in the favoriteitems dictionary.

The items you see are all set to being AlwaysVisible. You need to edit that file to add your own file.

I will give some links that might help you.

About the com.apple.sidebarlists.plist file, http://www.thexlab.com/faqs/finder.html

Finding the com.apple.finder.plist, https://discussions.apple.com/thread/4122582

Another post, https://apple.stackexchange.com/questions/139305/how-can-i-add-new-folders-to-the-favorites-in-the-finder-sidebar

About editing a file in Electron

There are tutorials about how to edit files with Electron, you can start from this example, https://ourcodeworld.com/articles/read/106/how-to-choose-read-save-delete-or-create-a-file-with-electron-framework

Fatih Aktaş
  • 1,446
  • 13
  • 25
  • 1
    I guess this was the case in older macOS, but it seems not to be working anymore. That's why I posted the path to the file that I'm interested in - this is the one that I actually need to modify to add something to the `Favorites` list – mdmb Sep 26 '18 at 22:45
0

What I've done is I wrote a python script based on the resource that @Royson posted in this question's comments (click).

It's available under a gist: https://gist.github.com/Ancinek/6d6e34791c5a8674275560ae118848c7

Currently possible to add/remove one file at a time.

I will be creating a binary for this so it can be run without the need to installing the pyobjc on the user's machine - will post the update soon after I find out how to actually do this.

Hope this helps somebody!

mdmb
  • 4,833
  • 7
  • 42
  • 90