Script to select workspace

Thanks @ngan for your kind words and the description. Easy :slight_smile:

Re Suggestion: add workspaces to sidebar, make dynamic for flagging the loaded workspace, there is an easy method that only required creating one dummy file for only once (I think).

(1) Create a dummy file anywhere in any database, and gets its uuid, but never delete it. (2) Also drag and drop the dummy to the “Favorites”. (3) Add two more lines of script to ur workspace-loading script.

Every time you change the workspace, the dummy filename changes accordingly.

Just a suggestion.

tell application id "DNtp"
	try
		set theWorkspaces to workspaces
        -- get the dummy that is under "Favorites", I just make-up an arbitrary uuid here
        set wsFlag to get record with uuid "3874ABCB-2073-46A9-ABA4-730A8BF70C40"

		set mychoice to (choose from list theWorkspaces with prompt "Load this workspace" default items "None" OK button name {"Load"} cancel button name {"Cancel"})
		if mychoice is not false then
			set theSelection to item 1 of mychoice
			close every think window
			load workspace theSelection
            -- or any naming format you'd like to use
            set name of wsFlag to "*Workspace: " & theSelection
		end if
	end try
end tell

Learn a new trick from u today…
FYI, you can put the script between these two words:

  your script 

Thank you.

Yes, even DevonThink doesn’t have to be active with this script.

So then, a save script would just have to access that file, read its name to be able to update the correct workspace. Very clever!

Does the file need to be in favorites though? I tried it without, and it worked. And that way, it could be hidden away somewhere.

Just want to make sure that I’m not misleading you. The added lines just change the name of the dummy to reflect which workspace has been loaded coz you mentioned that you forget which workspace is loaded sometimes.

No, the dummy doesn’t need to be in favourites. Just that I thought you may want to see that right in the sidebar. It is one possible idea and there is no need to waste too much time on it…

No, I get it. It’s using the dummy file as a way to store the currently active workspace. I just made the following script to update the current workspace.It looks up your dummy file, trims out the name of the workspace from it, and saves the current workspace to it.

tell application id "DNtp"
	try
		--change uuid to the item link of your dummy file
		set wsFlag to get record with uuid "043DA815-DB89-46D5-A0B7-D403D724365E"
		--assumes the name of this file is "*workspace: " + the workspace name
		set wsName to the name of wsFlag as text
		set wsName to ((characters 13 thru -1 of wsName) as string)
		save workspace wsName
		beep
		
	end try
end tell

I’m not a fan of using “characters 13 thru -1” to strip out the prefix, but I couldn’t find a simple command to remove a substring. Anyone have a suggestion for how remove a substring (e.g. "*workspace: ") from a longer string (e.g. “*workspace: savedname”)?

1 Like

This is phantastic! Thank you for sharing.

An AppleScript noob asking:
How do I always save to the current workspace?

@dansroka By chance, do you know if it’s possible to limit the windows that DEVONthink saves for a given workspace? For example, is it possible to only save the frontmost window or those on your current desktop/space?

Like yourself, I use a lot of workspaces (and use a similar script, which I feed into Alfred to make the selection and saving of workspaces a little easier). At any given time, I usually have a few different workspaces open - which makes updating them tricky (i.e., because it requires opening a closing the windows that aren’t associated with a particular workspace). In any case, given your use of workspaces, I just thought you might have a trick for this. Thanks for your help!

Sorry, I don’t know the answer to that! Maybe someone else…?

No it’s not possible. A workspace will remember every open window. If you don’t want a window included, close it.

Thanks for your help @dansroka and @BLUEFROG!

@cgrunenberg Any chance we could get this option added to the AppleScript dictionary?

Any variation of the following would be great:

  • save workspace NAME for think windows LIST
  • save workspace NAME from frontmost think window
  • add think window X to workspace NAME (which would add the window to the ones already saved by the workspace)

Thanks for your consideration!

We’ll consider this for future releases depending on overall interest.

1 Like

+ 1

I tried workspaces several times but there must be something wrong with them in the current state, at least for me. Would really like to make use of them.

BTW is there a reason that the dictionary is missing a property that returns the current workspace?

1 Like

No requests so far? :slight_smile:

Wow! Then this is the first request :slight_smile:

Added to the first build of version 3.7.2.

2 Likes

What is ”wrong with them”?

Not sure, maybe accessibility. But with a “current workspace” property it will be possible to write a script and assign a shortcut. I prefer spending some time to set things up and afterwards never think about them again rather than digging around in menus :slight_smile:

It sometimes seems you’re waiting all day for a feature request :grinning:
Thanks a lot, really looking forward to 3.7.2! And 3.7.1 is very nice!!