Page 1 of 2
Close a tab by it's name, caption or location
Posted: 19 Nov 2013 22:42
by klownboy
Hi Don, I'm not sure if you ever saw this post, but would it be possible for you to enhance the SC "tab" get operation such that we can perform tab operations (e.g., close) directly when we input the tab's caption or location or index?
Code: Select all
tab([operation], [data], [index|name|caption|location])
or at least be able to obtain the tab index directly with that information. Currently we have to loop through all the indexes to find a match for the caption (see highend's example in the second post). Yes, XY scripting is quick in doing that, but it really seems to make sense from a practical standpoint that we should be able to perform operations like closing a tab directly when it's caption is known.
For background, I've automated the opening of a new tab whenever I insert a flash drive. The tab(s) have the flash drive's label for a caption (e.g., Cruzer (I:)) using the new SC get("drivename", [path], 1). I'm using Uwe Sieber's USBDLM which allows you to run an XY script upon inserting the Flash Drive. Even if XY is not running it will start XY and open a new tab with the drive's name as the caption. USBDLM also detects the removal of a drive so I have another script which will disconnect the drive using Uwe Sieber's RemoveDrive and then remove the associated tab in XYplorer.
Thanks,
Ken
Re: Close a tab by it's name, caption or location
Posted: 19 Nov 2013 23:20
by highend
I don't think it's too hard to use a bit of scripting for it.
Code: Select all
$tabToCloseCaption = "TestTab";
while ($i++ < tab("get", "count")) {
$tabCaption = tab("get", "caption", $i);
if ($tabCaption == $tabToCloseCaption) {
tab("close", 0, $i);
}
}
But if your really need specific commands I can move this thread to the Wishes subforum...
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 00:12
by klownboy
Thanks very much highend. Since I didn't see anything in tab help that used the tab's caption, name or location as a field for closing a tab I figured it would take some looping with the indexes to close the tab. Though, I was hoping there was an easier way. That's a few steps just to close a known tab, isn't it? It would seem to make sense that we should be able to directly close or make current a tab by the tab's caption/name/location, maybe a new "data" field for the tab's name/label in addition to the index. I suppose it would save looping through 18 tabs to find the right one. I have the tab's index when it is created currently in another script, but maybe I can combine the 2 scripts or maintain the tab's index as a short-time perm variable.
Thanks again,
Ken
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 00:51
by highend
How should a command, that closes tabs by caption (known by relying on an internal list/array/dictionary) behave when there are tabs that have the same name, or caption, or etc.?
Btw, looping through 18 tabs takes 15 msecs (on my machine)

Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 12:49
by klownboy
Hi highend, I have no issues using what you provided above to get the tab index based on it's caption and I do believe what you say about the speed. XY on my Windows 8.1 machine consistently opens (for the first time in a session) in approximately 330 ms and an XY scripting menu with many subs loads even faster. So no issues with speed once-so-ever. I just thought it made practical sense that we should be able to perform operations on a tab based on it's name/caption or location and not have to hunt down the index first.
I'm not sure why anyone would have multiple tabs with the same name especially if it was the same location. I'd make sure the name was different slightly if the location was the same. For scripting purposes, if that was the case, I'd either delete both tabs with the same caption or the first encountered (I wouldn't care) unless they can be distinguished by location or something else. Someone using a command such as this in scripting should know enough (or better) that it shouldn't be an issue. In any case, you'd have the same problem with the method you provided above, wouldn't you?
Thanks again,
Ken
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 14:23
by highend
I just thought it made practical sense that we should be able to perform operations on a tab based on it's name/caption or location and not have to hunt down the index first.
I'd never said it does not
In any case, you'd have the same problem with the method you provided above, wouldn't you?
It's far more easier for me to do specific things if I stumble over when (in a while / foreach loop) than a (rather)
general function.
I guess in the end Don's internal things operate on the index of a tab, too.
So the modified function should look like this?
Code: Select all
tab([operation], [data], [index|name|caption|location])
I'll better move it to the Wishes subforum, ok?
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 16:18
by klownboy
highend wrote:I'll better move it to the Wishes subforum, ok?
That's fine with me...it seems logical to be able to do what we're asking.
By the way, I spent the last hour looking over the documentation for USBDLM. It's quite powerful. I'm about ready to load the service for the first time after spending some time modifying the ini file. I'm curious to see what kind of resources it consumes, at least in comparison to USBDeview that I toyed with yesterday. The USB Drive Info Tool that's supplied with it certainly helps with the device IDs, etc. Thinking of the sequence of events, it seems like it would make sense to use their "RemoveDrive" utility to actual start the process to actually disconnect the drive maybe via a CTB in XY and then USBDLM would take over and run the script which would remove the associated tab in XY (now with a label).
Thanks,
Ken
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 17:51
by highend
-- Moved--
USBDLM.exe & USBDLM_usr.exe take about 2MB
It's a good way to let USBDLM remove the tab(s) inside XY at least if it should be fully automated.
Post your script when it's ready

Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 19:11
by klownboy
Yes, USBDLM is very light in resources, lighter than USBDeview. Thanks for mentioning it. I've been using his "removedrive.exe" but until now not USBDLM.
I'm having an issue automating though. I have USBDLM open a script which assigns a drive NAME using the new function. Which works well on the first flash drive installed, but for the next one installed, since the script uses a foreach loop after get("drives", 2), it will assign another tab with the same name as the first along with making a new tab for the second drive installed. So I have to prevent that from happening. I'd like the new tab to have the drive name and letter. I wonder if I can have the script smarter by obtaining the drive or drive volume name in a "variable" fed back from USBDLM or I have to prevent a new tab from being created if one already exist. I see in your example posted, you have a XY one line script running as so.
Code: Select all
DeviceID1=USBSTOR\DISK&VEN_256MB&PROD_USB2.0FLASHDRIVE
open="<path to your>\XYplorer.exe" /script="::tab("new", "%drive%");" /flg=2
I'd like to do something as simple as that with the drivename and letter for the tab, but I'm having no success with that either even testing from the AB ...something like
Code: Select all
open="D:\Tools\XYplorer\XYplorer.exe" /script"::tab("new", "<drivename %drive% 1>");" /flg=2
Running this
Code: Select all
::tab("new", <get drivename "J:\" 1>);
gives me "<drivename>" in the new tab even though when stepping though it show the proper "drivename" obtained by get. The error states the location is currently not available when I run it and the location it gives is D:\tools\XYplorer\Transcend (J:) which obviously isn't right (i.e., it's trying to create the new tab with a location of off my XY folder

My USB ports are getting a lot of abuse testing this out!

Sorry for being a pain.
Thanks,
Ken
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 20:26
by highend
I'm unsure if I get what you're trying to do...
tab("new", <location>)
Does that one really allow <drive name>|<path>?
Does this line inside the usbdlm config work for you?
open="<path to your>\XYplorer.exe" /script="::tab("new", "%drive%");" /flg=2
Or in other words: Is the %drive% correctly resolved inside XY?
http://www.uwe-sieber.de/usbdlm_help_e.html#variables
doesn't list %drivename% as one of usbdlm's variables.
Did you try %Label% or %VolumeLabel% instead?
If everything fails, why don't you just supply the %drive% and let the passed script find the volume name and rename the tab afterwards?
Btw, it's much easier to try those things in a VMware because you can mount / dismount usb drives with 2 clicks for a VM. No physical ejecting and reinserting all the time...
Re: Close a tab by it's name, caption or location
Posted: 20 Nov 2013 23:56
by klownboy
highend wrote:tab("new", <location>)Does that one really allow <drive name>|<path>?
Probably not (from my testing) hence the wish. I figured I'd try it because you had %drive% in your post (example), but I guess you're not doing that. Maybe it will if we get our wish.
I haven't toyed with the USBDLM variables (e.g., VolumeLabel) much yet. It would be nice if they could carry over into the outside environment. I added this line referred to in help to the ini file, but I may have to reboot to see if they made it to the Windows environment.
Code: Select all
"From the help: These variables can also be made available as environment variables for processes started by USBDLM.
Which variables are required must be configured"
UsbdlmVariablesToOpenEnvironment=DevName, VolumeLabel
So, I think this means we can use these variable in the "open" line in USBDLM such as a command line parameter but not in the XY script itself.
Anyway, I got the inserting of a flash drive to work fine (i.e., new tab made with the drivename as the caption) invoked via USBDLM [OnArrival10]. I haven't had enough time to solve my issue with installing additional drives (i.e., prevent a second new tab from being made for the initial drive when installing the second drive).
The script for removing the drive (using removedrive.exe) and the associated tab also works, but currently that script is being started by pressing a CTB/menu (which is fine with me). However, I have to resolve what happens if I don't eject the drive via a CTB/XYplorer script. For example if I simply eject the drive from the tray, there wouldn't be any need to remove a tab if I wasn't using XYplorer or XY wasn't running. Though I might want to remove an XY tab if XY was running but not "active" and the drive eject was invoked down in the tray. In that situation the script could be invoked via [OnRemoval1] in USBDLM. As you well know, it can be a bit bit confusing depending on how the drive is ejected.
Thanks,
Ken
Re: Close a tab by it's name, caption or location
Posted: 25 Nov 2013 17:54
by klownboy
Updated and hopefully clarified the first post...
Thanks,
Ken
Re: Close a tab by it's name, caption or location
Posted: 26 Nov 2013 19:51
by klownboy
- Restarting a Safely Removed Flash Drive in Windows -
highend wrote:Btw, it's much easier to try those things in a VMware because you can mount / dismount usb drives with 2 clicks for a VM. No physical ejecting and reinserting all the time...
I've been doing some searching and researching and found a method of remounting or restarting a flash drive which was safely removed but not physicaly removed from it's port. A one liner script such as this will restart/remount the flash drive for use. Note: You could buy a program like "USB Safely Remove" or "Zentimo", but they do the same thing - disable and enable the HUB - as well as take up resources.
Code: Select all
run "cmd /c D:\Tools\DevCon\devcon.exe disable USB\ROOT_HUB20&VID8086&PID3A3A&REV0000 & D:\Tools\DevCon\devcon.exe enable USB\ROOT_HUB20&VID8086&PID3A3A&REV0000", , 2, 0;
Essentially, it disables and enables the USB hub that you select. Unfortunaltely though Microsoft's Device Control, devcon.exe does not come in the Windows installation. The proper latest version of "devcon.exe" is not so easy to get. You have to get it (free) from the WDK package.
http://www.microsoft.com/en-us/download ... x?id=11800 Also see:
http://stackoverflow.com/questions/7671 ... ve-drivers
You can obtain the proper HUB designation by going into device manager, select View "Devices by connection" and find the correct USB root HUB (there are going to be a few). If you have a flash drive installed but was safely removed, it will help determine the correct USB Root HUB since the USB Mass Storage Device below it will have a will have an exclamation point. Double click on the "USB Root HUB" for that device and then go into "Details" and use the dropdown to get to "Hardware IDs". This will provide the proper USB HUB designation you'll have to use in devcon.exe (see above example). Once you've obtained devcon.exe you can look at these examples on it's use.
http://msdn.microsoft.com/en-us/library ... s.85).aspx I've extracted "devcon.exe" for Windows 7 x64 if you want it. This site explains the process
http://www.raymond.cc/blog/remount-ejec ... -reinsert/
Ken
Re: Close a tab by it's name, caption or location
Posted: 30 Dec 2014 16:08
by klownboy
An update to this old thread. Uwe Sieber's very excellent
Drive Tools have been updated such that his
RestartSrDev now will restart most USB flash or external hard drives. Previously you had to use something like Microsoft's
DevCon utility to re-enable or restart a USB drive which had been "Safely Removed" but left plugged in.
When used along with his also excellent
USBDLM you can fully control your USB drives via XYplorer. For example you can plug in a USB flash drive or external hard drive and have XY automatically open a new tab with the name of the drive. When you're done using the drive you can click a CTB and have XY eject the drive (i.e., safely remove it) and remove the XY tab just mentioned.
If you forgot to copy a file to or from the USB and you haven't yet physically removed it, you can also set up the script such that a right-click of the same CTB will restart the device for use. I can post some example small scripts and excerpts from the USBDLM ini file if there's any interest.
Happy New Year!
Ken
Re: Close a tab by it's name, caption or location
Posted: 04 Jun 2015 11:55
by LittleBiG
Hi Don, I'm not sure if you ever saw this post, but would it be possible for you to enhance the SC "tab" get operation such that we can perform tab operations (e.g., close) directly when we input the tab's caption or location or index?
+1 I would like to join to this request. The tab command uses either the current tab or a tab referred by its index. But there is no possible easy way to get an index of a tab by its caption. Please!