File access from Zotero plugin in Zotero 7

122 views
Skip to first unread message

jl

unread,
Aug 4, 2023, 5:29:57 AM8/4/23
to zotero-dev
Hi,

I am having problems with file access from a zotero 7 plugin. Not sure what the problem is so maybe someone can help with this. From a plugin, the `OS.File.stat` line below doesn't trigger any errors but the code below is never gets executed (I see message 1 but not 2). This is from a function wrapped in Zotero.Promise.coroutine. 

testFunction: Zotero.Promise.coroutine(function* (path) {
    Zotero.debug("Message 1");
    var file_stat = yield OS.File.stat(path);
   Zotero.debug("Message 2");
});

However, from Tools->Developer->Run Javascript, I can run the same code without problems. I can even use run javascript to replace the function in the plugin with exactly the same code and it runs afterwards.

Could this be related to file access issues? Any other ideas?

Thanks!

Francisco Bischoff

unread,
Aug 4, 2023, 6:32:02 AM8/4/23
to zoter...@googlegroups.com
I think OS.File is not accessible for addons.

Try Zotero.File.*
--
Francisco Bischoff



"Innovation and creativity comes from assembling pieces from other stuff in weird ways."
-- Ben Chestnut, Founder of MailChimp



--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotero-dev/8eb7029b-aebd-438a-b75b-e8e66879524fn%40googlegroups.com.

iseexuhs

unread,
Aug 4, 2023, 6:34:21 AM8/4/23
to zotero-dev
you need import osfile, try this:

Components.utils.import("resource://gre/modules/osfile.jsm");

Dan Stillman

unread,
Aug 4, 2023, 6:34:41 AM8/4/23
to zoter...@googlegroups.com
Make sure you're checking debug output and the error console — you're
almost certainly getting an "OS is not defined" error, since you didn't
import osfile.jsm.

But OS.File and OS.Path are actually going away in Firefox 115, so file
operations that can't use Zotero.File methods should use IOUtils and
PathUtils instead. I've added those to the plugin sandbox for beta 28,
which will be out in the next hour.

Relevant documentation is here:

https://firefox-source-docs.mozilla.org/dom/ioutils_migration.html
https://searchfox.org/mozilla-esr102/source/dom/chrome-webidl/PathUtils.webidl

I've added a note to the documentation.

Also note that you shouldn't be using Zotero.Promise.coroutine()/yield
for anything anymore. Just use async/await.

jl

unread,
Aug 4, 2023, 7:31:08 AM8/4/23
to zotero-dev
Four responses in one hour. Thanks everyone!
Reply all
Reply to author
Forward
0 new messages