如果您必须使用文件夹的自定义图标,如何以编程方式将文件夹图标放在 Finder 侧边栏上?

发布于 2024-07-25 17:41:14 字数 155 浏览 6 评论 0原文

目前正在开发一个项目,虽然我可以通过添加到 com.apple.sidebarlists.plist 文件然后重新启动 Finder 来添加侧边栏项目,但我似乎不知道如何使用指定的自定义图标显示文件夹图标。

谁能给我指出一个可以让我这样做的链接或解决方案? 提前谢谢大家!

Am currently working on a project, and though I can add sidebar items by adding to the com.apple.sidebarlists.plist file then restarting Finder, I can't seem to know how to make the folder icons show up using its assigned custom icon.

Can anyone point me to a link or a solution that would make me do this? Thanks a bunch in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

善良天后 2024-08-01 17:41:14

没有受支持的方法可以使用纯可可来执行此操作。 请改用 LSSharedFileList API。 这是管理侧边栏列表的受支持方式,并且您可以在插入项目时提供自定义图标(作为图标服务中的 IconRef)。

There's no supported way to do this using pure Cocoa. Use the LSSharedFileList API, instead. It's the supported way to manage the sidebar lists, and you can provide a custom icon (as an IconRef from Icon Services) when you insert an item.

猫性小仙女 2024-08-01 17:41:14

我不知道图标,但我使用 EBLaunchServices 包装器将项目添加到侧边栏,该包装器在此处提供开源:

https://github.com/Eric-Bro/EBLaunchServices

它非常容易使用。 例如,要将已安装的 OSXFUSE 卷添加到侧边栏,您可以调用:

NSURL* volumeUrl = [NSURL fileURLWithPath:@"/Volumes/MyVolume"];
[EBLaunchServices addItemWithURL:volumeUrl toList:kLSSharedFileListFavoriteVolumes];

I don't know about the icons but I add items to the sidebar using the EBLaunchServices wrapper which is available open source here:

https://github.com/Eric-Bro/EBLaunchServices

It is very easy to use. For instance to add a mounted OSXFUSE volume to the sidebar you call:

NSURL* volumeUrl = [NSURL fileURLWithPath:@"/Volumes/MyVolume"];
[EBLaunchServices addItemWithURL:volumeUrl toList:kLSSharedFileListFavoriteVolumes];
旧情勿念 2024-08-01 17:41:14

我太固执了,不能不做显而易见的事情。 我做了:

[[NSWokspace sharedWorkspace] setIcon:someIcon forFile:someFile options:0];

设置文件夹的图像图标。 从那时起,我进行了 com.apple.sidebarlists.plist NSUserDefaults 附加操作,并通过 Apple Events 重新启动了 Finder。 这使得一切顺利。

I was too stubborn to not do the obvious. I did:

[[NSWokspace sharedWorkspace] setIcon:someIcon forFile:someFile options:0];

to set the image icon for the folder. I from then I did com.apple.sidebarlists.plist NSUserDefaults appending, and restarted Finder through Apple Events. That made it all work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文