Is there a way to get the list files/folders/drives in the macOS sidebar?
Take a look at this file with a plist editor:
~/Library/Preferences/com.apple.sidebarlists.plist
Mine appears to have years and years worth of old drives, folders, etc. that aren’t in my sidebar anymore.
It turns out I’m looking for
~/Library/Application Support/com.apple.sharedfilelist/
and inside that folder is a bunch of .sfl4 files, and I’m not sure how to read them.
Is there no API for the information you seek?
Reading files manually tends to be the wrong way to do things in the Apple ecosystem.
The files are binary plists.
Tim Parnell is not wrong. An API would be better but sometimes there is no other way.
I have no idea what the API would be called, let alone how to look it up.
I asked for some help understanding this StackOverflow answer, and it seems there was an API but it’s deprecated. I’m not sure I’d be comfortable with a “reading other app files” solution, but if it works for you, it may be the only thing you can do.
Please check out both links above and decide what approach you’d like, it looks like ChatGPT is ready to help you write a solution that can read those files.
I saw someone say that they managed to do it via AppleScript, but it turned out to be user interface scripting (move mouse here, double-click at these coordinates) and not a replicable solution.
My hunch is that Apple considers the sidebar to be pretty intimate to the usr and not something another application will need to be modifying - plus, if they did, it’s just one more permission/entitlement, maybe one more category in the Privacy section of System Settings, etc.
Looks like I’ll forget about it for now. I thought there’d be a simple way to make a dual-pane finder browser with a sidebar that would be filled with the list from the Apple sidebar. But it looks like the sidebar will be a royal pain.
I had to do something similar, last week. I wanted to get the size of each connected disk of a given Mac, along with the volumes it contains (mounted or not).
So I asked ChatGPT and explicitly asked to avoid shells and parsing; I told it I can use the MBS plugins. It first ruled out MBS as it doesn’t have all the required classes and then proposed a solution using IOKit. The provided code had errors, which it attempted to fix (several times after I reported issues to it), and eventually, it told me it can’t be done that way in Xojo and that the preferred way (regardless of the language) is to use the diskutil command and parse the result using the XML classes of Xojo.
This alternative was not straightforward either, because of unexpected bugs in Xojo’s XML classes, but it finally worked. I’ve never been comfortable using shells (rather than API calls, which will always seem more reliable and direct to me), but, sadly, they can’t always been avoided.
I looked around and I don’t think there is an API for this. Diskutil seems to be the authoritative way of doing it.
Maybe it would help to think of a shell as a socket to a service, where you send commands and receive responses. Ignore the fact that you’re launching a small executable - just focus on the results.
Thanks for having also looked.
The major issue I have with shells isn’t really the fact that I’m relying on another executable (while it’s true it counts), but parsing strings to construct data just never seemed reliable to me (the format of the string may change between releases, for example).