简体   繁体   中英

ElectronJS - adding folder to favorites [macOS]

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...

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");
});

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM