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.)
  • @dstillman, you wrote "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.) "

    I tried to install keyconfig in Zotero 5.0.69 using the link on the keyboard shortcuts documentation page. https://www.zotero.org/support/kb/keyboard_shortcut

    It didn't work. Is there a way to install keyconfig on an updated Zotero?
  • edited July 24, 2019
    I don't think you can just install keyconfig in Zotero, and I don't think this is what @dstillman has meant. Instead, I understand his comment as a suggestion for a new feature that would work in a similar way.
  • Yes, that's right.

    I think it was possible to run some version of keyconfig in Zotero at one point, but that may have been only in Zotero for Firefox, or a much older version of Zotero Standalone and/or keyconfig.

    For now, if you use the Run JS window often, I'd just recommend keeping a collection of snippets in a text file.

    (As for keyconfig-like functionality, I don't know when we'd get to it ourselves, but if someone is interested in working on it, we can certainly discuss.)
  • I would love keyconfig-like functionality in Zotero. My current attempts to use it with keyboard alone involve AutoHotKey, but that doesn't work for a number of functions for various reasons.

    I wish I could program a plug-in for this. Since I can't, let me know if there is any way I could help someone's efforts to create this in any way.
Sign In or Register to comment.