DT4 b2: AppleScript “load workspace” oddity

Running macOS 15.4.1, I use a short Alfred workflow to launch DEVONthink. It is simply a keyboard shortcut linked to the following AppleScript:

tell application id "DNtp"
activate
load workspace "Diaries"
end tell

If I load the “Diaries” workspace within DEVONthink (i.e., when it is already running) it correctly shows “Smart Rules” and “Smart Groups” collapsed in the navigation sidebar. However, when it is run via the code I have mentioned it shows those expanded. Further, on each occasion it does so it adds an identically named workspace to the list under DEVONthink → Window:

The same thing happens if I run the script from Script Editor. (The identically named workspace is not added if I load the workspace within DEVONthink.)

I’m rather at a loss as to why that happens so helpful comments are welcome!

Stephen

The load workspace command doesn’t automatically close windows, therefore new windows having new settings are used in this case. See e.g. Open Clean Workspace… script available via the Help > Support Assistant how to avoid this.

It’s not a new workspace, just a new window. See above.

Thanks for the prompt reply and explanation. I have tried using the script you mentioned but it invariably seems to leave me with a number of DT windows (through which I can move using CMD + backtick). In other words the AppleScript command close every window appears not to have the desired effect. (I wonder whether it’s a timing issue?)

At present the best workaround for me is what I previously used: to ensure I quit DT in the form I’d like it to launch. That is no hardship so please don’t devote time to this small problem!

Edited to correct AppleScript command.

Stephen

Does this work?

tell application id "DNtp"
	activate
	close every think window
	load workspace "Diaries"
end tell

That still leaves me with one additional window open.

Stephen

What kind of window?

Sorry, first I should have said that your latest suggestion was an improvement—in that I had only one additional window open. I did not mean to sound unappreciative!

Um…er…it’s pretty much a duplicate of the window I want:

(I do get terribly confused with the technical window names in DEVONthink!)

Stephen

Close all windows, then open the workspace using Go > Workspaces > … - does it open one or two windows?

One.

Does DEVONthink use its own space and the Script Editor.app is in another one?

Not so far as I am aware! I never work in more than one space on my Mac.

Edit: Confirmed: both are in the Desktop space.

Stephen

Does this script close all main & document windows? At least it does over here (macOS 15.4.1).

tell application id "DNtp" to close every think window

When I run that and right click on DT in the Dock, choosing Show All Windows I’m told there are "No Available Windows”.

However, when I run your previous script (with DT quit, of course) the same procedure (right click on Dock icon) shows two windows open.

I’m sorry this is proving such a challenge. Please don’t worry if we can’t for the moment resolve the issue. I don’t want to ruin your day!

Stephen

For what it’s worth, I created an entirely new workspace, using another database, and the result of running your script using that workspace is the same in terms of open windows: there are two.

And do you execute the script in the Script Editor.app or via Alfred? I tried only the Script Editor.app but that’s always successful over here.

Since this thread started, only in the Script Editor app.

Stephen

One further clue, maybe…

With this code:

tell application id "DNtp"
	activate
	close every think window
	delay 2
	with timeout of 3600 seconds
		close every database -- There is the potential this may not close a database if it's actively syncing.
	end timeout
	load workspace "Diaries"
end tell

running from Script Editor still gives me two windows—one “Inbox” and the other the requisite “Diaries - 2025” window. If I remove the Delay command I end up with two identical “Diaries - 2025” windows.

Does removing the line activate make a difference?

Sadly not.

In that case I’m running out of ideas as it’s working as expected over here.