C-Command Software Forum

Can’t access messages in a mailbox with AppleScript?


I was trying to generate a textual list of flagged messages (almost all in mailboxes). I tried both creating a Smart Folder as well as using the “flagged” tag in the records list directly, but either way it seems that EagleFiler does not consider a message in a mailbox a selected or even a visible record, as only a message that was in a file by itself was considered a “record”.

Is there any way to get metadata about selected messages via AppleScript?

The workaround I eventually found was to export all the messages to a .mbox file and use a MBOX to CSV script.

Currently, messages in mailboxes are not scriptable at all, except that you can ask EagleFiler to open x-eaglefiler links to them. I think I initially couldn’t decide how I wanted to model messages in mailboxes (since they wouldn’t have all the same properties or commands as other records) and then the case for this got to be way down in the list. Today, it seems like I should probably just make a separate AppleScript type, and then you could get the selected records, selected messages, or selected items (both mixed together). How does that sound?

Thanks - good to know this was by design.

The problem with calling them “selected messages” is that you can also have messages outside a mailbox mixed in with messages in a mailbox. I guess you could call them “selected mailbox messages” but that’s a mouthful.

If possible I’d suggest mirroring the UI as much as possible where EagleFiler doesn’t distinguish visually between messages in mailboxes and messages outside of them. If certain attributes didn’t return anything useful for a message in a mailbox, I’d understand - in this case all I wanted was from/subject/date.

Yeah, the UI goes to a lot of trouble to treat them as consistently as possible. OK, that makes sense to return missing value if not applicable or raise an error for attributes that can’t be set.

Two other issues that I recall now:

  • Currently, library record uses numeric IDs, but it would have to switch to string IDs in order to identify messages that are inside mailboxes. I can pretty easily change this internally, but I’m not sure whether it would break any scripts that depend on the way IDs currently work.

  • There’s an option in the UI to choose whether the Records source shows messages that are in mailboxes. It can be overwhelming and slow if you have millions of messages to see them all in the same list. The same issue (but worse) will exist in AppleScript if you ask for every library record. It doesn’t seem like AppleScript should respect the view option, especially since it’s per-window. But you may not always want to have everything returned to the script or loaded into the Script Debugger explorer.

Those both make sense to me. Not sure about the IDs of course, as I can’t exactly audit all the scripts that use EF. Maybe change it in a beta and see?

Agree that “every library record” is dangerous and can’t personally see any use for it! As long as you document this limitation in the docs/scripting dictionary I suspect it’d be fine. I have never enabled that option in the UI, for what it’s worth.

Yeah, I think we’ll just have to try it.

I suspect that people are implicitly using it to get a particular record based on its name:

set _r to library record "name"

Under the hood, AppleScript will ask for all the records in the library, whereas:

set _r to library record "name" of root folder

will only look at the files at the top level. I guess, worst case, there could be a scripting property on the library itself that controls whether you get everything.