Differentiating Between QuickReference Windows in a Script

Hi,

I’m trying to use applescript to paste text from other applications into Scrivener documents that are opened in QuickReference windows. The problem I’m running into is that I haven’t yet figured out how to refer to a specific window of the several that are open (so that I’m currently only able to paste text into whichever window last had the focus).

I’ve tried using tell window 1, tell window 2, etc. to no avail. I’ve also tried using tell document “title”, also to no avail thus far.

Anyone have any thoughts for me?

Scrivener doesn’t yet have a full AS dictionary, so it might just not be possible to target QR windows, since these are palettes, not full windows (they disappear when you tab out of Scrivener). I could be wrong about that, but whatever the answer is, it will probably be answered in general AppleScript usage, nothing specific to Scrivener.

Just out of curiosity, it sounds like you are replicating the Services features to a degree? They don’t target the QR windows either, but will append text to the currently focussed document (either its main text, or its notes), as well as make new documents in the binder as “clippings”. You might want to check those out in §11.2 (pg. 84).

Hi Ioa,

Thanks for the prompt response.

I’m down with the Services, but have a different use-case here.

Definitely no luck getting the QuickReference windows identified. When I do a test script to get the properties of Scrivener’s windows, regardless of which or how many QuickReference windows I have open, the script always locates 4 Scrivener windows - 1 is unnamed but presumedly the main window, 2 is whatever document was last selected in the binder, 3 is Snapshots, and 4 is Preferences.

So my question now becomes, is it possible via applescript to target specific documents within Scrivener - i.e. something like the Append service, but to a particular document rather than to the currently-focussed document. I’ve looked through the applescript dictionary for Scrivener 2.0, but don’t quite get how to target a document within a Scrivener project.

For example, for a document called “Waystation” in a project called “2010.11.01 - Scrivener 2.0 Test”, applescript returns the following properties: {zoomed:true, miniaturized:true, name:“2010.11.01 - Scrivener 2 - Waystation”, document:document “2010.11.01 - Scrivener 2.0 Test” of application “Scrivener (2.0)”, miniaturizable:true, class:window, closeable:true, resizable:true, visible:false, zoomable:true, id:11659, bounds:{0, 22, 1280, 796}, index:2}

Can I use any of that to target my desired document, rather than the focussed document?

Yeah, that’s the kind of thing that you really need an AppleScript enabled application to do. The general, global AS dictionary is only suitable for extremely basic usage and will have no awareness of any internal data models, like items buried in the binder (which, in the vast majority of cases aren’t even loaded into memory at all, to save resources). So yeah, trying to use a QR panel seems like a reasonable workaround, except that those aren’t “Windows” in AppleScript nomenclature.

Getting AS supported in Scrivener is one of the priorities on the list for the coming year; until then this type of stuff just probably won’t be feasible.

Oh, and the Window name you pasted isn’t going to be of use for this matter—it’s just getting that name from the window title itself, which changes as you click on things. What you need is access to the data model, and that will require specific AS hooks, coded for Scrivener, to work.

Thanks, Ioa.

I will make do with what the solution I’ve puzzled together so far, and eagerly look forward to Scrivener’s AS support.