!! The code below is provided "AS IS". Usage is completely at your own risk. No warranties from my side. !!
(Download of the newest version from close to the bottom of this post.)
Even more details
Regarding the available downloads below
Release notes / Change log
Possible ideas for the future
here is a script written in AutoHotkey (AHK), which works in combination with XY and Windows Explorer (from now on called "WE"). Please, see the credits section further down for all the cool people who helped in one way or another so far, e.g. with testing, bug fixing, suggestions and motivation.
The script was written for the following scenarios:
(1) XY's setting "XY is default file manager" not getting respected:
Despite XY's build-in optional functionality to act as the system's default file manager (XY menu Tools/Configuration/Other/Shell Integration), sometimes there still are WE windows opening instead of XY (e.g. from within certain 3rd-party-software or for other reasons).
(2) List items not getting automatically selected in XY:
At other times XY *is* sucessfully used as the system's default file manager to open a folder (if that setting is on) but any list itmes which would normally be selected in WE do *not* get selected in XY (e.g. when clicking in Firefox in the "downloads" window on the "open containing folder" button).
For such scenarios, this script, if running in the system tray, catches any newly opening WE window, reads the path and selected items shown in that WE window, closes that WE window, opens a new tab in XY with that path *and* selects any list items in XY that where selected in WE before (and scrolling them into view), thus "redirecting" the WE window to XY.
The script will stay in the system tray until manually exited through the script's tray context menu.
Some of the scripts settings can be easily customized by the user. These settings are located in a separate config file, named "redirectWEwindowsToXY_v#.config.ahk", with "#" standing for the first two parts of the script's version number, e.g. “4.1“, which the config file is compatible to. It is part of the download.
For the script to work also in cases of scenario No. (2), of course, the XY setting to act as the system's default file manager must be turned *off*.
If one wants any WE windows to be kept as WE windows (and *not* be redirected to XY) - e.g. control panel stuff - then there are these options:
Hold the left or right control key pressed down while the WE window opens, which you want to keep. Typically, though, the control key must be held down until the WE window has actually opened. If released too early, it might not work as intended.
With the script running, pressing Win+E would open a new WE window which normally would get redirected to XY.
Pressing Control+Win+E, the new WE window would *not* get redirected to XY. (Of course the Control-key-escape option should work also if a WE window is opened by other means.)
This functionality of the control key can be activated or deactivated on its own (just in case) in the script's system tray context menu.
(2) Pre-defined keywords / paths:
The script allows for pre-defined keywords and paths, which are compared to the location being displayed in the WE window (typically the content of the WE address bar, e.g. "Computer", "Libraries", "Pictures" ... and paths without trailing backslash). These keywords and paths can be either set in the variable vWindowsExplorerPaths in the separate config file "redirectWEwindowsToXY_v#.config.ahk" - separated by the pipe character "|". Else they can also be passed to the script as command line parameters - separated by spaces (and quoted if they contain spaces). Both kinds of definition *are* allowed together at the same time.
Example for the command line parameters option:
In case of command line parameters (or parameters passed in the target line of a windows shortcut file) the command line could look like this:
"path_to_autohotkey.exe" "path_to_script.ahk" Computer Libraries Pictures "C:\some kind of folder\another folder"
In the separate config file "redirectWEwindowsToXY_v#.config.ahk" there are some suggestions for keywords to be used on an English version of Windows.
The variable vKeepOrRedirect_matchingWEPaths in the separate config file "redirectWEwindowsToXY_v#.config.ahk" determines what will happen in case of a match (when comparing the WE window's location with the keywords/paths definitions). It must be set to either "Keep" or "Redirect". If vKeepOrRedirect_matchingWEPaths is set to "Keep", then the matching WE windows are kept as WE windows (and the others are redirected to XY). If vKeepOrRedirect_matchingWEPaths is set to "Redirect" then the matching WE windows are redirected to XY (and the others are kept as WE windows).
The method for comparing the WE window's location with the keywords/paths definitions, can either be set to use Regular Expressions (RegEx), which is recommended due to its ability to formulate general patterns. To do so, the variable vUseRegExForPathCompare in the separate config file "redirectWEwindowsToXY_v#.config.ahk" must be set to 1. Else, if vUseRegExForPathCompare is set to 0, then - to be a match - a keyword or path and the WE window's location must be identical.
Of course, if RegEx is used as a compare method, then also the keywords and paths must be specified using RegEx syntax.
Here are some helpful sites for learning RegEx (PCRE flavor):
If RegEx is used as a compare method, then any additional keywords/paths specified in the extra variable vExceptionPathsInCaseOfRegEx in the separate config file "redirectWEwindowsToXY_v#.config.ahk" act as a subset of exceptions to the main keywords/paths definitions specified in vWindowsExplorerPaths. Therefore, the main definitions in vWindowsExplorerPaths can contain a more general pattern and the extra variable vExceptionPathsInCaseOfRegEx can contain exceptions from that general pattern. (This is *only* available for the compare method RegEx.)
Even more details
WE windows, which show the content of a zip file, are automatically kept as WE windows if the "identical" compare method is used. This is, because XY does not support this kind of view and the "identical" compare method is not capable of defining zip files as a pattern. However, if RegEx is used as compare method, then the user must specify it manually in the RegEx pattern if he/she wants a zip file-content-view to be kept in WE (e.g. with \.zip$ either as part of a Keep-pattern or as part of a exeptionPaths-when-Redirect-pattern).
If XY is not running it will be started automatically if the path to XYplorer.exe is specified correctly. The path can be specified in the variable vPathToXYplorerForAutostart in the separate config file "redirectWEwindowsToXY_v#.config.ahk". A tooltip close to the mouse cursor will indicate the starting process of XY. If the XY autostart should not work for some reason (e.g. if the wrong or no path is specified) the script will display a message box and wait for the user to start XY manually.
If the user wishes for the script to apply auto-redirection also to all WE windows already existing at the moment of the script's start (not just to newly created ones while it is running) then this can be activated in the variable vApplyRulesToExistingWEwindowsAtScriptStart in the separate config file "redirectWEwindowsToXY_v#.config.ahk". Setting the variable to 1 will activate that behaviour. Setting it to 0 will deactivate it.
In order to manually redirect a given WE window to XY by force (regardless of the rules for automatic redirection), the user can specify a hotkey in the variable vHotkeyInWEwindowsToTriggerRedirectionToXY in the separate config file "redirectWEwindowsToXY_v#.config.ahk". (A hotkey refers to pressing a combination of keys on the keyboard, namely a character key together with one or more modifier keys. Modifier keys are Control, Alt, Shift and the Windows key.) The WE window will be redirected if the hotkey is pressed while the WE window is active. More details on how to specify the hotkey are given right next to the variable itself.
This hotkey can be activated or deactivated on its own (just in case) in the script's system tray context menu. If no such hotkey is specified, then the system tray context menu item will not exist.
The whole script with all its functionality can be suspended in the script's system tray context menu or with a global hotkey, which can be specified in the variable vHotkeyGlobalToSuspendUnsuspendTheWholeScript in the separate config file "redirectWEwindowsToXY_v#.config.ahk".
-) Whenever a WE window is "redirected" to XY, it will still open for a short moment in a normal way and immediately be closed again. For this script to work, I do not know of any way how to avoid that.
-) In case of multiple XY windows being open at the same time, the most recently active XY window will be used for redirection.
-) This script has not been tested with WE add-ons, which add tabs to WE.
Regarding the available downloads below
I removed the compiled exe version of the script from the available downloads again, which I had attached in a previous version.
I really don't want to promote downloading and running executables from some stranger on any forum (including me right here). This can be dangerous and such exe files should never be trusted. Besides, if there is something going wrong on the computer at the users end, then I want the user to be able to check and see (and me to be able to easily proof - protecting myself) that there was no malicious code in my script, which would not be possible, if I offered an already compiled exe.
Instead, I want to encourage everyone to download the AutoHotkey base program from here: https://www.autohotkey.com/download/ and run my ahk file (which is inside the zip attached to this post - see below) with that AutoHotkey program. The AutoHotkey program can either be installed the traditional way and set to run ahk files on double click (which is the default). Else, just unzip the zip downloaded from the AutoHotkey website and create a Windows shortcut to the included AutoHotkey.exe with the path to the ahk file downloaded from here as command line parameter in the shortcut.
Alternatively you can compile the ahk-script yourself. It is really simple. Just download and install the AutoHotkey base program. Then right-click on the ahk-file, which you downloaded and extracted from the zip here, and choose "Compile Script" from the right-click menu. This will create a compiled exe of the ahk-script in the same location. That's it. It is that simple.
(And if you want to include the icon in the compiled exe, then - after installing the AutoHotkey base program -, instead of right-clicking on the ahk script file, go to the start menu, choose the AutoHotkey folder and start the little helper app "Convert .ahk to .exe". In the dialog of that app, state the "Source (script file)", where to save the "Destination (.exe file)" and which "Custom Icon (.ico file)" to use. Click "> Convert <". Done.)
P.S.: Most of the code was written years ago. Looking at the code now, it does not look pretty at all. I feel a need to rewrite it from scratch but don't have the time nor the motivation for it all at the moment. For now, I just started a little bit and mostly changed the things, which seemed to me most important. In a later version I might rewrite the code - or not.
Here is the newest version for download ("AS IS", usage at own risk):
The download includes all the description as comments at the beginning of the code.
For all versions: copyright by autocart (user name at the ahk and XYplorer forums) unless otherwise noted in the code
Change log below.
Here are older versions:
First of all, not all AHK code used in the script was writting by me. I am specifically pointing out in the code itself, where I got it from if it was from someone else. Other than that, all the following cool people helped so far (as of 2020-05-05) with e.g. testing, bug fixing, suggestions and motivation, as can also be seen in the thread below:
Dustydog (Special thanks to Dustydog for motivating me to pick this baby back up after a couple of years! This also shows that posting to a year's old thread is not bad at all but can be very good.)
Release notes / Change log
Changes in version 4.1:
-) Added the variable vHotkeyInXYtabsToTriggerRedirectionToWE to the config file to specify a hotkey to manually redirect a tab in XY to WE (which is the opposite direction than usually). This hotkey only works in XY.
It can be set to the same hotkey as vHotkeyInWEwindowsToTriggerRedirectionToXY is set to, which only works in WE, so that the hotkey serves as kind of a toggle-hotkey between XY and WE. (As suggested by Dustydog, see viewtopic.php?f=7&t=10671&p=178249#p178248)
In case that a view in XY does not have a real path (e.g. "My Computer" or XY paper folders), WE for now always opens with the "My Computer" view.
-) Added the variable vCloseXYtabIfRedirectedToWE to the config file to specify whether or not the XY tab should be closed if it is redirected to WE.
In case that the view in XY does not have a real path, the XY tab is not closed, regardless of this variable.
-) Internal change: Changed the function name ShellMessage_forCtrlWinE to ShellMessage_keepTheNextWEwindow.
Changes in older versions:
Code: Select all
Changes in version 4.0 - 200501: -) Moved the user customize section out into a separate .config.ahk file. (As suggested by 1024mb, see https://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=10671&start=45#p177998) This helps the user to not have to update the user customizeation part of the script each time a new version is released. Plus, it is easier to keep the overview in a much shorter file without the distraction of the intro or the main code below. The new .config.ahk file carries the first two digits of the version number of the script version, which it belongs to, in its name, e.g. “4.1“. The main version and/or the first sub-version number of the script (and thus the name of the .config.ahk file) will from now on be incremented only, if the compatibility of the .config.ahk file changes. When the script is updated but the compatibility with the config file stays the same, only the 3rd part of the script's version number will be incremented, e.g. “4.1.2“. (At first I was about to increment only the script's main version number each time the config file would change, but realized that there might still be a considerable amount of new user settings to come?, so the chances that the main version number would go up fast seemed to risky to me.) -) Added a check for the script file's encoding and the encoding of the new config.ahk file. If they are not saved in the UTF-8 format with BOM, then the script will pop a message box and refuse to run. -) Added a global hotkey, specified in the variable vHotkeyGlobalToSuspendUnsuspendTheWholeScript in the .config.ahk file, which will suspend or unsuspend the script. (As suggested by Dustydog, see https://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=10671&start=30#p177771) -) Added a tray menu item which toggles the use of Ctrl to manually keep a WE window (just in case). -) Renamed the tray menu items a bit. Changes in version 3.4.1 - 200430: -) Fixed a bug with none-ascii characters. Saved the script file as with UTF-8 *with* BOM. Before it was saved as UTF-8 without BOM, which caused none-ascii characters to be processed incorrectly. Changes in version 3.4 - 200429: (only bug fixes) -) Maybe fixed that XY sometimes crashed when being autostarted. When XY was autostarted it sometimges crashed, as it seems, without the line "WinWait, XYplorer ahk_class ThunderRT6FormDC", which is strange to me because the code before that line should have aleady made sure that the XY window exists. However, it did not always crash. Re-added that line in for now, nevertheless. So far, it never crashed on autostart with that line. -) Fixed / Changed (hopefully improved) the way how paths, which are being redirected to XY, are passed to XY. There could have been problems with how paths were compared to the existing tabs. Especially if the redirected path was a sub path of an existing tab, it would have not opened a new tab but changed the current tab to the new path. -) Fixed a bug by which the script would send XY into a scripting error, if the redirected path contained single quote characters. -) Fixed a bug that if a path was redirected to XY and the list in XY did *not* have focus, then any selected items in WE would be selected in XY but not be scrolled into view. Now they are (respectively the first selected item is). -) Fixed a bug preventing to manually force redirect zip content views to XY. -) Fixed / Changed the way how paths, that are really files (e.g zip files), are handled when passed to XY. There was an inconsistency in the code how such paths were handled, which could have led to XY displaying nothing in a new tab. This was highly unlikely to surface to the user, but might have after the fix above. Now, if the path is really a file, then the path to the parent directory of that file is always taken as the redirected path and the file as selection. Changes in version 3.3 - 200428: -) Fixed some wrong logic in the processing of events. Previously, if XY was not already running, it would be automatically started also if the WE window was to be kept as WE window. In that scenario also, if no correct path to XYplorer.exe was specified, then the script would still pop the corresponding message box and wait for XY to be started manually. This made not even any sense, since the WE window would anyway not be redirected to XY. This is changed now. The script will only check for the open XY window and react accordingly if the WE window is to be redirected. -) Fixed a logical bug with RegEx compare: If hard coded keywords/paths were used AND command line parameters AND RegEx was used as compare method, then there was a logical bug which could have led to everything being a match (besides the RegEx-exeptions) -) Changed the order of the help text a bit. Adjusted the order of the variables in the "USER CUSTOMIZE SECTION" of the code accordingly. -) Added the variable vApplyRulesToExistingWEwindowsAtScriptStart to optionally apply the specified rules also to existing WE windows at script start. -) Added the variable vHotkeyInWEwindowsToTriggerRedirectionToXY to be able to specify a hotkey to redirect WE windows to XY manually, if pressed while the targeted WE window is active. -) Simplified the system tray context menu to three items: (1) Toggle menu item to use/activate the specified hotkey for redirecting WE windows manually (or deactivate it). (2) Toggle menu item to Pause / Suspend Script which both pauses the script and suspends the hotkeys. (3) Fully exit the script. Changes in version 3.2 - 200425: -) Added code for an optional custom tray icon and supplied a simple icon with it. -) Renamed the variables; especially the variable with all the keywords and paths is now called vWindowsExplorerPaths. -) Added the options/variables vKeepOrRedirect_matchingWEPaths, vUseRegExForPathCompare and vExceptionPathsInCaseOfRegEx. -) Added some visual marking of the user customize section in the code below -) In case the variable vKeepOrRedirect_matchingWEPaths has an incorrect value, a message box will pop. -) Changed the hard coded behaviour of *not* redirecting the display of the content of zip files to XY: Now it is only hard coded for the case if RegEx is *not* used as compare method. If RegEx is used, then the behaviour for zip files can be specified in the RegEx pattern. Changes in version 3.1 - 200424: -) Fixed the problem that the script would crash if XY was not active. -) The path to XY can now be specified in the variable $pathToXYplorer at the beginning of the code. -) In case of a XY autostart process, a tooltip will be diplayed close to the mouse cursor. -) In case the XY autostart process could not be started, a message box will pop. Changes in version 3.0 - 200423: -) Improved reliability: Before, the script sometimes missed WE windows or seemingly could not retrieve its path and then did not react as expected. -) Improved behaviour when paused: Now the script is respecting the script's paused state (see the script's system tray context menu) in that it stops redirecting when the script paused. (As suggested by Dustydog, see https://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=10671&start=30#p177771) Before it ignored the state of being paused and redirected anyway. -) Changed the behaviour of the script regarding already existing WE windows: In previous versions, when the title bar of already existing WE windows (which existed prior to the scripts start) changed (e.g. when changing a folder in such a window or when refreshing by hitting F5), then the script also used to redirect such WE windows to XY. Not anymore. Now, if a WE window already exist at the scripts start, the script leaves it untouched. -) Added a Control-key-escape option: If the left or right Control key is pressed while a WE window opens, then this particular WE window will *not* get redirected to XY.
-) make a separate help/readme file
-) maybe handle also other message scenarios - not just "window created"
-) maybe re-introduce automatic redirection of existing WE windows while browsing the file system in that WE window. I think, this has pros and cons. The pros are that if I specifially browse to a path which I want to open in XY it will be done automatically. The cons are that if I browse to a path which gets redirected to XY, I might have forgotten to think of it and might not want that at this very moment. I think for now, the new hotkey feature with which it is possible to manually force-redirect the current path/view in an WE window to XY, might be the best solution. But I am open for suggestions.
-) improve the MsgBox popping when the WE path could not be determined (maybe with debug-information that a user could then post in the forum for my knowledge) and make it easier for the end user to disable that MsgBox if he/she would want to not see it
-) add a compatibility check for the found config file; in case it is not there or it is an old version, offer the user to create a new config file with default values.
-) add a setting which allows the user to have the WE windows be redirected to an XY throw-away-clone instead of the main XY window
-) adding to the throw away clone idea: somehow let the user optionally specify a layout to be used with the throw away clone
-) adding to the throw away clone idea: implement a functionality to move the throw away clone window tab to a main XY window tab. and vice versa.
-) adding to the throw away clone idea: allow the user to specify, which WE windows get redirected to a throw away clone window in XY and which get redirected to the main XY window
-) ... to be continued ...
The list above are just brainstorming results and not a real roadmap, just saying. For any suggestions of improvement I am grateful (whether they are aleady included in the list above or not), because I want this script to be of help to many users. Many thanks in advance!