Option Explicit dim wasSpecial Function OnInit(initData) initData.name = "KHSpecialFolderHandler" initData.version = "1.0" initData.desc = "Do something when entering specified folders and something else when exiting, depending on where to" initData.copyright = "(c) 2015 Leo Davidson + mods by aussieboyke for khalidhosain" initData.default_enable = true Dim vecDefFolders Set vecDefFolders = DOpus.Create.Vector ' Default folders / example config used for testing / modify here or via scripts preferences vecDefFolders.push_back("/homeroot\testfolder") ' Thumbnail size can be changed in settings initData.config.ThumbNailSize = "384" initData.config.SpecialFolders = vecDefFolders initData.config_desc = DOpus.Create.Map( _ "ThumbNailSize", "Thumbnail size to apply to special folders.", _ "SpecialFolders", "Special folders which trigger the action.") End Function ' Helper Function Function IsPathInVector(fsu, path, vecFolders) IsPathInVector = False ' Resolve aliases, libraries, etc. to their real/absolute paths. path = fsu.Resolve(path) Dim testPath For Each testPath in vecFolders If (fsu.ComparePath(path, fsu.Resolve(testPath))) Then IsPathInVector = True Exit Function End If Next End Function Function OnBeforeFolderChange(beforeFolderChangeData) ' Use a script level variable to "remember" whether coming from special or non special folder wasSpecial = IsPathInVector(DOpus.FSUtil, beforeFolderChangeData.Tab.Path, Script.config.SpecialFolders) Script.vars("wasSpecial") = wasSpecial End Function Function OnAfterFolderChange(afterFolderChangeData) If (Not afterFolderChangeData.result) Then Exit Function ' Folder didn't change. End If ' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script. ' If (afterFolderChangeData.qualifiers <> "none") Then ' Exit Function ' End If Dim cmd, cmdstr Set cmd = DOpus.Create.Command cmd.SetSourceTab afterFolderChangeData.tab If (Not IsPathInVector(DOpus.FSUtil, afterFolderChangeData.tab.Path, Script.config.SpecialFolders)) Then ' Hard coded action to apply to folders not flagged as special If (Script.vars("wasSpecial")) Then DOpus.output "Action = " & afterFolderChangeData.action If (Not afterFolderChangeData.action = "normal") Then cmdstr = "Set Format=!folder" DOpus.output "Previous folder was special, so " & cmdstr cmd.RunCommand cmdstr End If End If Else If (Not afterFolderChangeData.tab.format.view = "thumbnails") Then ' Hard coded command to meet KH requirement for thumbnail mode in special folders cmd.RunCommand "Go CURRENT VIEW=thumbnails" Else ' Thumbnail size can be adjusted in settings cmd.RunCommand "Show THUMBNAILSIZE source," & Script.config.ThumbNailSize End If End If End Function