Divert "Marked Pictures" new tab to existing tab

If you use the image marking function of the viewer in its default mode, when the viewer closes a new tab will open showing the marked pictures collection. This script lets you divert that new tab to open the collection in the existing tab (the one the source images came from) - meaning that the Back button will then work to take you back to the source folder.

Note that because of limitations in the scripting interface this is slightly clumsy - the new tab opens, then closes again. We are looking at a way to streamline this in the future.

  • To use this script, paste it to a .vbs file in your script add-ins folder (/dopusdata/Script AddIns).

  • If you're using a non-English language version of Opus, or have changed the name of the Marked Pictures collection in Preferences, you'll need to edit the Const MarkedPicturePrefix line at the top of the script to tell the script what to look for.

option explicit

' if the "Marked Pictures" prefix isn't correct for your language/configuration you will need to edit this string
Const MarkedPicturePrefix = "Marked Pictures"

' MarkedCollectionSameTab
' (c) 2017 jpott

' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.

' Called by Directory Opus to initialize the script
Function OnInit(initData)
	initData.name = "MarkedCollectionSameTab"
	initData.version = "1.0"
	initData.copyright = "(c) 2017 jpott"
'	initData.url = "https://resource.dopus.com/viewforum.php?f=35"
	initData.desc = "Make marked collections open in the same tab as the source images"
	initData.default_enable = true
	initData.min_version = "12.0"
End Function

' Called when a new tab is opened
Function OnOpenTab(openTabData)

	' see if this is a "marked pictures" folder. if the "Marked Pictures" prefix isn't correct
	' for your language/configuration you will need to edit the string
	if Left(openTabData.tab.path, 7 + Len(MarkedPicturePrefix)) <> "coll://" & MarkedPicturePrefix then
		Exit Function
	end if

	' find first item in that collection
	Dim rd
	Set rd = DOpus.FSUtil.ReadDir(openTabData.tab.path)
	if rd.complete then
		Exit Function
	end if
	Dim item
	Set item = rd.Next
	' find a tab showing that item's path
	Dim tab, existing_tab
	for each tab in openTabData.tab.lister.tabs
		if tab.path = item.path then
			Set existing_tab = tab
			exit for
		end if
	if not isempty(existing_tab) then
		' read the folder into the old tab
		Dim cmd
		Set cmd = DOpus.Create.Command
		cmd.RunCommand("go """ & openTabData.tab.path & """")
		' close the new tab
		cmd.RunCommand("go tabclose")
	end if
End Function
1 Like