简体   繁体   English

ElectronJS - 将文件夹添加到收藏夹[macOS]

[英]ElectronJS - adding folder to favorites [macOS]

I am wondering if there is a way to add a folder to Favorites using Node? 我想知道是否有办法使用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. 你可以使用try os模块。 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. 您可以使用com.apple.sidebarlists.plist首选项文件在Mac上编辑侧栏。 The items will be in the favoriteitems dictionary. 这些项目将在收藏夹词典中。

The items you see are all set to being AlwaysVisible. 您看到的项目都设置为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 关于com.apple.sidebarlists.plist文件, http://www.thexlab.com/faqs/finder.html

Finding the com.apple.finder.plist, https://discussions.apple.com/thread/4122582 查找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 另一篇文章, 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 关于在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 有关于如何使用Electron编辑文件的教程,您可以从这个示例开始, https://ourcodeworld.com/articles/read/106/how-to-choose-read-save-delete-or-create-a-文件与-电子框架

What I've done is I wrote a python script based on the resource that @Royson posted in this question's comments ( click ). 我所做的是我根据@Royson在这个问题的评论( 点击 )中发布的资源编写了一个python脚本。

It's available under a gist: https://gist.github.com/Ancinek/6d6e34791c5a8674275560ae118848c7 它可以在一个要点下获得: 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. 我将为此创建一个二进制文件,这样它就可以在不需要在用户机器上安装pyobjc情况下运行 - 在我发现如何实际执行此操作后很快就会发布更新。

Hope this helps somebody! 希望这有助于某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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