Stop AppleScript opening multiple windows for the same record

I have an AppleScript that finds the record I’m looking for and opens it in DT, using the command

set theTab to open tab for record x

The problem I am having (which seems to be new, though I may not have noticed before) is that if a window for record x is already open, it opens a new one. What I can’t work out how to do is check whether a window/tab for record x already exists, and if so, to set theTab to that, rather than generating a new one. Sorry, this is probably straightforward and I’m just being slow. At least, I hope so …

document window and current tab have properties that you can inquire. I’d use the record’s UUID to decide whether it’s already open or not.

I don’t know what I’m doing wrong but I can’t any of the relevant properties of the tabs.

set theTabs to tabs of think windows

returns a list, but trying to get the content record (or other property) of any of them fails. So does

return content record of current tab

ChatGPT has sorted it out for me

Here’s what I’d do in JavaScript

(() =>{
const app = Application("DEVONthink 3");
const windows = app.thinkWindows;
windows().forEach(w => {
  tabs = w.tabs();  
  tabs.forEach(t => console.log(t.contentRecord.uuid()));

But then I’m just HI 1.0

ChatGPT has sorted it out for me

In what way?

return content record of current tab

It’s better to examine the AppleScript dictionary to learn such things (especially instead of querying ChatGPT). The content record is a property of the application, tab, or window.

current tab is a property of a think window not the application.

Amended response.

1 Like

and in a slightly different idiom:

Application("DEVONthink 3")
    w => w.tabs().map(
        t => t.contentRecord.uuid()
1 Like