Close XYplorer window when removable drive removed?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
vertigoelectric
Posts: 21
Joined: 19 Jul 2016 07:43

Close XYplorer window when removable drive removed?

Post by vertigoelectric »

Currently when I'm browsing a USB drive in XYplorer, removing the drive will cause the XYplorer window to navigate to the "This PC" view (showing drives). Is there any way to get it to close the window instead?

When I need to plug/unplug the USB drive frequently, what happens is I end up with several open XYplorer windows because I get a new one each time I plug the drive in but they don't close when I unplug it. It ends up just being a nuissance.

Yes i know I can just close it manually, but often when working between machines and moving files via the USB drive, I just want to unplug it and go, without the 'cleanup' step each time.

Thanks!

PS: I tried disabling the option to show parent when folder is moved/deleted, but it didn't do the trick.

highend
Posts: 14158
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Close XYplorer window when removable drive removed?

Post by highend »

Not possible. You would need e.g. an autohotkey script that monitors the availability of
these mounted devices and closes XY instances automatically.

One other way would be the usage of http://www.uwe-sieber.de/usbdlm.html
which can execute commands when drives get available / removed...

Why don't you limit XY to one instance only?
[ ] Configuration | General | Startup & Exit | Allow multiple instances
One of my scripts helped you out? Please donate via Paypal

TheTodd
Posts: 14
Joined: 15 Sep 2016 12:54
Location: United States

Re: Close XYplorer window when removable drive removed?

Post by TheTodd »

I understand that you just want to grab your USB and go, but here is a script I use for ejecting drives. It closes tabs in the active pane that use that drive.. for some reason I don't do both panes, but that could be done easily too.

Also, if the script is run from a button with ctrl-click it shows all drives. I suppose that can be dangerous as it offers up all drives for ejection. I had to do that because for some reason, getting the list of removable drives does not show some of my memory cards that I deal with.

Anyways its here as inspiration for anyone looking for some removable drive scripting.

Code: Select all

"Remove Drive : removedrive"
   // RemoveDrive: http://www.uwe-sieber.de/drivetools_e.html
   // Set this path accordingly
   $removeDrivePath = "C:\Program Files\Utils\RemoveDrive\x64\RemoveDrive.exe";

   // Check if Control Clicked
   $shift = <get shift>;
   if ($shift == 2) {
     $startDrives = get("drives");
   }
   else {
     // Get list of removable drives
     $startDrives = get("drives", 2);
   }
   
   end $startDrives == "", "No drives to eject.";
   
   // Get drive names for each drive
   $driveNames = "";
   foreach($driveLetter,$startDrives) {
     $driveName = get("drivename", $driveLetter, 1);
     if ($driveNames == "") {
       $driveNames = $driveName;    // first one
     }
     else {
   	   $driveNames = $driveNames . "|" . $driveName;
   	 }
   }   
   
   $selectedIndex = inputselect("Select the drive to eject:", $driveNames, , 160,,,,"Eject Media");

   $selectedDrive = gettoken($startDrives,$selectedIndex,"|");
   $selectedName = gettoken($driveNames,$selectedIndex,"|");
      
   // Close tabs that use that drive   
   
   $tabCount = tab("get", "c"); // Only for the active pane
   while (true) {
      $tab = tab("get", "path", $tabCount);
      if (substr($tab, 0, 3) == $selectedDrive) {
         tab("close", 0, $tabCount);
      }
      $tabCount--;
      if ($tabCount == 0) { break; }
   }
   status "Ejecting $selectedName";
   run """$removeDrivePath"" $selectedDrive", , 2, 0;

   // allow some time to finish then check if drive is gone
   wait 1000;
   
   $endDrives = get("drives", 2);
   if ($startDrives == $endDrives) {
     status "Failed to eject $selectedDrive" , "" ,"alert";
     msg("Drive may not have been removed.<br>Removable drives still detected: ""$endDrives""");
   }
   else {
     status "Eject Success. ($selectedDrive)"
   }
the wait 1000 is a bit sloppy, but I wasn't sure a quick and dirty way to know exactly when the drive is ejected.

vertigoelectric
Posts: 21
Joined: 19 Jul 2016 07:43

Re: Close XYplorer window when removable drive removed?

Post by vertigoelectric »

Not possible. You would need e.g. an autohotkey script that monitors the availability of
these mounted devices and closes XY instances automatically.
I actually already use AHK for a lot of things. In fact, I have an AHK script that detects when a stock Windows Explorer window opens, then asks me if I want to reopen that location with XYplorer (because some applications open folders with Windows Explorer by force). Perhaps I can implement something that handles what happens when I remove a device...
Why don't you limit XY to one instance only?
[ ] Configuration | General | Startup & Exit | Allow multiple instances
I often work with several open XYplorer windows (another reason I'd like to reduce the number of unused windows) so I need to keep that option on.

I understand that you just want to grab your USB and go, but here is a script I use for ejecting drives. It closes tabs in the active pane that use that drive.. for some reason I don't do both panes, but that could be done easily too.

Also, if the script is run from a button with ctrl-click it shows all drives. I suppose that can be dangerous as it offers up all drives for ejection. I had to do that because for some reason, getting the list of removable drives does not show some of my memory cards that I deal with.

Anyways its here as inspiration for anyone looking for some removable drive scripting.
Thanks. That might be an option I look into.

Post Reply