Feature request: More options for the javascript runner

The ability to run arbitrary javascript code via the new javascript runner is extremely helpful, especially for things that don't really warrant for a plugin. Would it be possible to add a few more features to the runner that would make it even more useful:

For example:
1. A way to save and load scripts: I guess a common scenario involves having some scripts that are used on a regular basis, like for data transformation, merging, and similar things. It would be great if theses scripts could be saved directly in Zotero.

If 1. is possible:

2. A way to upon a script in an external editor.

3. Associate execution mode with a given file (run as async function)

  • Why isn't the code always ran as async? If there's no async code in an async function, it will just return an already-resolved promise, right?
  • It would be great if theses scripts could be saved directly in Zotero.
    To clarify, do you mean that the scripts would be saved internally, or that you'd be able to load/save files stored elsewhere from this window?

    The latter is what you see in Firefox's Scratchpad, but that seems fairly pointless to me when you can just copy and paste.

    The ability to store scripts in Zotero is interesting, though. One model here would be the old keyconfig extension for Firefox/Thunderbird, which let you assign custom code snippets to keyboard shortcuts. (I actually use that in Thunderbird many times a day to open the URLs for Zotero Forums posts, and it's incredibly useful.) The main downside would be the proliferation of code snippets that would likely eventually become obsolete and either break (at best) or cause damage (at worst, though unlikely), whereas extension code generally has a maintainer. But that might be a reasonable trade-off for most of the people who would actually take advantage of this sort of thing.
  • Why isn't the code always ran as async? If there's no async code in an async function, it will just return an already-resolved promise, right?
    We could consider this, but the displayed value is different. In non-async mode, the value of the last expression is shown, so var foo = 1; foo; shows ===>6<=== (number). In async mode, it's the resolved value of the promise, so you have to use var foo = 6; return foo;, which is a bit different from what you might expect from a REPL, Scratchpad, etc. On the other hand, almost all Zotero code where you would actually want to see a return value — as opposed to just triggering some action — probably does need to be async, so maintaining the standard behavior may not be worth it.
  • To clarify, do you mean that the scripts would be saved internally, or that you'd be able to load/save files stored elsewhere from this window?
    I was actually thinking of the first idea: store scripts internally. Being able to assign custom code snippets to keyboard shortcuts sound like a great idea.

    (@dstillman : Sorry for the late reply; I have gotten a email notification for emilianos first comment, but not for your comments. Is that how it should be or are there problems with the notification system?)
  • (You only get a notification for the first comment in a thread since the last time you viewed it, or if someone mentions you. Just click through on the email notification to make sure you're notified of a follow-up message.)
  • Ok, I see. So it is not really possible to follow the discussion via mail only. Good to know.
  • If saving scripts within Zotero is implemented as discussed above, how about including a few well-commented scripts for typical operations right there, as working examples? The users could just create a test library and have a play then.

    Separately, a tutorial would be great too, especially on how not to mess things up.

    Thanks for considering.
  • (I've moved the external scripts discussion to a separate thread.)
Sign In or Register to comment.