Someone posted a question on the AutoHotkey forum about running usccmd, and after finding this site I did some research and wrote a library that should make writing code for usccmd simpler. The code that I had originally posted here had several bugs in it, but Ryan has fixed them and posted an updated version a few posts down. Place usccmd.ahk in the same folder as your script. This requires AutoHotkey_L version 1.1.00.00 or newer to run.
Basic usage example:
;~ Include the library file at the top of the script:
;~ Then create a new usccmd object:
u := new usccmd()
;~ All commands return the text that is normally displayed in the command prompt window.
;~ To display a message with the list of devices:
MsgBox, % u.list()
To control multiple devices:
u1 := new usccmd("00001430")
;~ Or alternatively:
u2 := new usccmd()
u2.device := "00001431"
;~ Move device 00001430:
;~ Move device 00001431:
If usccmd isn’t in your system path and you need to specify it’s location manually:
u1 := new usccmd("", "C:\path\with\trailing\slash\")
;~ Or alternatively:
u2 := new usccmd()
u2.path := "C:\path\with\trailing\slash\"
The only thing that I know of that won’t work (based on what I can tell from the usccmd source) is that after you specify a device number, you won’t be able to use the list command on that object.
Thank you for posting this code! I tried it out and it works pretty well. My tests indicate that file names with spaces do need to be quoted. Can we post your code in our AutoHotkey Application Note and modify your code to make similar classes for our other USB products?
I updated it to put quotes around file names and I put the MIT license on it. You can post that code wherever you want. If you need any help making this work with the other USB products, let me know.
Thanks for updating it so quickly and making the code free. Unfortunately, the new version doesn’t work at all. The reason is commands like “usccmd --list “”” do not work. I wrote a new version that fixes this and while I was doing that I some other bugs:
- if p2 == 0, p2 is not added to the command.
- you need to specify the device like "u.device = “00000102"” not “u.device = 00000102”
- I am pretty sure the "return"s after MsgBox in the basic usage section, after “u2.device := 00001431” in the controlling multiple devices section, and after u2.path = … in the Specifying path… section are extraneous.
Here is my new line 83:
RunWait, % comspec . " /c """ . this.path . "usccmd" . (this.device ? " --device " . this.device : "") . " --" . cmd . (p1 !=""? (" """ . p1 . (p2!="" ? "," . p2 : "") . """""") : """") . " > usccmd_output.tmp",, Hide
When I ran usccmd --list and usccmd --list “”, they both seemed to work.
When you assign a number to a normal variable (device := 00000102), it doesn’t cut off the leading zeroes, but apparently when you assign it to an object (u.device := 00000102) it does cut them off unless you treat it as a string. That’s odd.
It does automatically return when it gets to the first hotkey definition. A lot of the scripts I write don’t have any hotkeys defined, so I just put those returns there out of habit.
You are absolutely right, I was wrong about what causes the problem. Your script generates this on my computer:
Which does not work. When I run that at the command line I get this:
I’ve developed a new line 83 that takes the quotes wrapping usccmd and just wraps them around the entire usccmd command:
RunWait, % comspec . " /c """ . this.path . "usccmd" . (this.device ? " --device " . this.device : "") . " --" . cmd . " """ . p1 . (p2 ? "," . p2 : "") . """"" > usccmd_output.tmp",, Hide
OK, I see now. I had tried running usccmd --list “” from the command line and it worked, so I changed my code. I guess I forgot to save the changes before I tested it because it was still working after I changed it, but I just tried it again and now it doesn’t.
Here is the updated version of the class.
usccmd.ahk.zip (2.02 KB)