user commands: examples and help

A collection of especially useful xplorer² topics and ideas. New users may find it helpful to look here before searching the other forums for information. >>>>>> Please post new material in the relevant forum. (New stuff posted here will be removed.) Thanks. -fg-

Moderators: fgagnon, nikos

profess
Silver Member
Silver Member
Posts: 307
Joined: 2003 Oct 06, 11:39

user commands: examples and help

Post by profess » 2009 Oct 01, 04:06

This thread was originally posted  in the xplorer² Professional forum.        
Moved here 25-May-2010 =fg=
=====================================================


Hi everyone,

Is it possible for you to post some example user commands, with a brief explanation of what they do?  For example

$ mkdir "$B"

creates a folder with the same name as the selected file.  A document selected called "project 123.doc" would create a folder named "project 123".  

I have also seen posts of scripts for extracting files from compressed archives, using 7-zip, winrar etc.  I am grateful for any examples and the more commands the merrier! :)

I learn best from having something to work from and learn best by seeing an example and tinkering with it.

----

Also, is there a way for user commands to do more than one command, i.e., for the mkdir example, is it possible to move the selected files to the folder that has been created?  I was able to do this with the Command Script, but not with User Command.

---

Regards all and thanks for any help,

Osei

User avatar
nikos
Site Admin
Site Admin
Posts: 14428
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2009 Oct 01, 05:02

there are too many possibilities. Most external tools that accept parameters from the command line will have their own special syntax. Many of them offer their own help e.g. $mkdir /? should give you a summary of the arguments it takes. Also checkout the blog, from time to time there are demo videos that utilize user commands

profess
Silver Member
Silver Member
Posts: 307
Joined: 2003 Oct 06, 11:39

thanks

Post by profess » 2009 Oct 01, 05:36

thanks for the suggestions and guidance.  I have looked into a couple applications which accept commands also.

everyone's use of x2 will vary to their needs, from the basic application of drag / drop files from one pane to the other, to more complex syncronising and user commands etc.  some of you guys are network administrators etc, whilst some are file managing on their pc. I miss taking command of the office's network - i'm a bit of a *geek* in that way.  :)  *sigh*, i miss the office (but not the politics!)

i am keen to know a few simple commands people use on a regular basis.

maybe that clears it up better.

thanks again,

Osei

User avatar
nikos
Site Admin
Site Admin
Posts: 14428
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2009 Oct 01, 06:45

i use windiff all the time to compare revisions of code between the working and the backup folder. This demo (near the end) shows how I do it:
http://www.zabkat.com/blog/wink/sync1.htm

in the normal case where I use windiff in normal xplorer2 windows (not scrap windows) the arguments i use are

> windiff $n $i

(instead of windiff $p $g as in the demo video). Scraps complicate a bit command execution since there is no concept of "current directory"

profess
Silver Member
Silver Member
Posts: 307
Joined: 2003 Oct 06, 11:39

windiff

Post by profess » 2009 Oct 01, 07:40

that explains windiff.  i guess its main use is for programming? apart from that i don't think there's much else to compare (the odd word doc, but even then it's stretching it).

that was a good one...

any more???

Mr.Pleasant
Silver Member
Silver Member
Posts: 281
Joined: 2006 Dec 29, 12:56
Location: Utrecht, NL

Post by Mr.Pleasant » 2009 Oct 01, 20:17

Interesting thread. I hope more people will reply, sharing their favorite user commands.
Here's mine:

Simple ones, kind of short-cut commands:
Character map:

Code: Select all

> charmap
Registry editor:

Code: Select all

> regedit
Mouse control:

Code: Select all

> main.cpl
Opening selected document(s):
Notepad++:

Code: Select all

>> "[path to notepad++.exe]" "$F"
Renamer (this command is not the best option; read on for a better option):

Code: Select all

>> "[path to renamer.exe]" /enqueue "$F"
WinDirStat:

Code: Select all

> "[path to WinDirStat.exe]" "$P"
WinMerge (compares left and right pane):

Code: Select all

> [path to WinMerge.exe]" /r /x /s "$L" "$R"
A bit more complex:
7-zip to zip selected folder(s) to the opposite pane:

Code: Select all

>> "[path to 7z.exe]" a -tzip "$I\$N.zip" "$N\"
7-zip to unzip selected zip(s) to the opposite pane:

Code: Select all

>> "[path to 7z.exe]" x "$N" -o"$I" -r
7-zip: test selected archive(s):

Code: Select all

$$ "[path to 7z.exe]" t "$F"
Create new folders in the opposite pane with the same names as selected folders:

Code: Select all

$$ md "$I\$N"
Then I have a couple of commands that start up customised .bat, vb-scripts or autoit-scripts.
The simplest is this:
Open selected document and a document with the same name in the opposite pane in their associated app (it's awfully lazy, but it can be useful for comparing many documents):

Code: Select all

> "[path to the .bat file explained below]" "$F" "$I\$N"
The .bat file referred to in the command above just contains:

Code: Select all

%1
%2
I'll see if I can post some more.
Last edited by Mr.Pleasant on 2009 Oct 03, 19:09, edited 1 time in total.

profess
Silver Member
Silver Member
Posts: 307
Joined: 2003 Oct 06, 11:39

Thank you very much

Post by profess » 2009 Oct 01, 23:12

Mr. Pleasant,

Thank you very much for your examples and uses. I will tinker with the commands when on pc! :) :) please send more if you have them.

From what I understand the ">" symbol is for executing apps, like you showed charmap and regedit?

And "$" is for dos commands? But only one action can be performed using User Commands?

I need to look into bat files again. Do bat files act a bit like Command Scripts? Can bat files be associated with User Commands?  

Osei

Mr.Pleasant
Silver Member
Silver Member
Posts: 281
Joined: 2006 Dec 29, 12:56
Location: Utrecht, NL

Post by Mr.Pleasant » 2009 Oct 02, 18:22

"$" is for dos commands, that's right! ">" is for those commands you'd normally use in the command line (like when you go 'Start' - 'Run...'). A good thing about that one is that you don't get or need a DOS console window.
I think only one command can be used in each user command, indeed (oh well, is that a feature request I feel coming up: user commands with the comma-separated syntax, like we know it from the Script-Wizard...? :turn: ). That's why I use bat files, which are text files with the .bat extension, containing several dos commands.
You can associate them in User Commands, in much the same way as I did in my last example (> "[path to the .bat file]")

You can find a lot about it in the X2 user manual: page 188 and further, and page 210. If you'd like to recapitulate what dos used to be about, have a look at http://www.computerhope.com, which contains a good reference.

I'm happy to be of help!
david

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: Thank you very much

Post by Kilmatead » 2009 Oct 02, 21:11

profess wrote:But only one action can be performed using User Commands?
As far as I know, yes, though speaking of feature requests, it might be nice if inline the C language <A> ? <B> : <C> conditional expression could be parsed.

As an example (as the command itself is just a normal application call, it's not very special, but Profess expressed an interest in how a batch file might come into play, so here goes):

I frequently use an audio editor called Goldwave (slightly more professional than Audacity, slightly less overblown than Soundforge).

Code: Select all

> "C:\Program Files (x86)\GoldWave\GoldWave_Record_If_NoFiles.bat" $s
In simplified form, the batch file contains:

Code: Select all

if (%1)==() goto nocontent

if  not exist %1 goto nocontent
"C:\Program Files (x86)\GoldWave\GoldWave.exe" /nosplash %1 %2 %3 %4 %5 %6

exit

:nocontent

"C:\Program Files (x86)\GoldWave\GoldWave.exe" /nosplash -new -record

exit
Basically, what I wanted was if Goldwave is invoked with selected files, it would simply open them - however, if no files were selected, it would default to immediately recording instead (saving me the trouble of manually configuring it).

Unfortunately invoking a batch file from a user command opens a superfluous DOS window... a simple way to prevent this is just to convert the .BAT to an .EXE (there are plenty of utilities available to do this, just Google it).  .VBS is also a viable alternative to batch, though a bit more of a hassle ('createobject("WScript.Shell")' blah blah blah, etc.)

One will also note that batch files don't automatically pass on multiple selected files, so it's necessary to redundantly express "%1 %2 %3..." and so on, just in case more than one is passed from x2.

Addendum: If Nikos is still conscious, the second line of "if not exist" is necessary to circumvent x2's Dr. Who's Arsed Parse bug.  :yuck:

User avatar
nikos
Site Admin
Site Admin
Posts: 14428
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2009 Oct 03, 05:25

i thought you could execute multiple user commands if you separate them with commas as usual, but that doesn't seem to work :confused: -- it works for batch file templates though

is that something that would please the flock?

also since the last version you can choose whether to execute a user command only for the focused item (==once) or by using >> or $$ prompt to apply the template on all selected items

finally if you have really complex logic then the windows scripting host is your natural goal

Mr.Pleasant
Silver Member
Silver Member
Posts: 281
Joined: 2006 Dec 29, 12:56
Location: Utrecht, NL

Post by Mr.Pleasant » 2009 Oct 03, 10:53

i thought you could execute multiple user commands if you separate them with commas as usual, but that doesn't seem to work - it works for batch file templates though
It works for batch file templates (command script, ctrl+b, whatever) only, not for user commands or commands in the addressbar. Your suggestion would please this part of the flock  :wink: . I surely would find use for Kilmatead's suggestion as well, if that would be feasible somehow...

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Post by Kilmatead » 2009 Oct 03, 11:21

Also, a couple of anomalies of note:

If invoking Office Word, when using $N it should always be encased in quotes as "$N" else any filenames which include spaces will be separated into multiples of their component words - i.e., opening a file named "This is a test.doc" will result in Word attempting to open "This.doc", "is.doc", etc.  Which is, to say the least, impractical.

For some reason this doesn't happen with $S, which by way of obscure contrast, ought never be used in quotes, as all the filenames will be treated as one big name, and most programmes will gurgle a choking death knell.  (Such as Mr. Pleasant's example above using Notepad++, you could replace the "$F" with $S [no quotes] and invoke it with a single ">" to accomplish the same thing.  Just a variation.)

One might also note that some programmes respond differently to ">" and ">>"... again, the Notepad++ example above works as expected either way, the one instance of the application simply tabs the files sent to it - whereas something like the image editor Gimp would actually open multiple instances of itself (and all it's attendant windows) using ">>", while ">" will simply tab each photo more practically (using $S).

If you run into unexpected results using one method, try the other.  Not all applications monitor multiple instances of themselves and the results can be goofy at best.

I did say these were anomalies, borne of that long-suffering midwife, Experimentation.  :?

Robert2
Gold Member
Gold Member
Posts: 593
Joined: 2004 Jun 17, 15:39

Re: Thank you very much

Post by Robert2 » 2009 Oct 03, 11:49

profess wrote:One will also note that batch files don't automatically pass on multiple selected files, so it's necessary to redundantly express "%1 %2 %3..." and so on, just in case more than one is passed from x2.
Have you tried using the DOS "FOR" command?
Something like this:

Code: Select all

FOR %%f IN (*.*) DO "C:\Program Files (x86)\GoldWave\GoldWave.exe" /nosplash %%f
Now here are a few more tips from http://command-line-programming.suite10 ... or_command:
"There are a few more options that can be used with file processing and the FOR command.

Using FOR to Process Lists of Files
The /D switch may be used between the FOR keyword and the variable name to limit the selection of files to folders. This might be useful in performing selective backups, for example. The /R switch can be used to walk the current directory tree. This will cause the command to recurse into each folder that it finds, and look for files that match the criteria.

Using FOR to as a Looping Construct
With the /L switch, it is possible to execute a command a given number of times based on a variable set that has a start, step and end value. The command will loop through the values, starting at start adding step at each iteration, and then stopping when the current value is equal to, or greater than end.
To loop forwards:

Code: Select all

for /L %%A in (0, 1, 10) do echo %%A
It is also possible to loop backwards:

Code: Select all

for /L %%A in (10,-1, 0) do echo %%A
And also, step by a different amount:

Code: Select all

for /L %%A in (0, 2, 8) do echo %%A
Note that all that has happened in this usage is that the file set has been replaced by a numerical set of values.
Debugging FOR loops can be quite tricky, and so a good debugger such as the Running Steps IDE is useful for stepping through the code."
HTH.

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: Thank you very much

Post by Kilmatead » 2009 Oct 03, 12:15

Robert2 wrote:Have you tried using the DOS "FOR" command?
Something like this:

Code: Select all

FOR %%f IN (*.*) DO "C:\Program Files (x86)\GoldWave\GoldWave.exe" /nosplash %%f
That works too, and would be a better method, though at the cost of invoking multiple instances of the object application, if said application doesn't monitor itself.

I settled on the blunt redundancy method simply because most programmes will automatically tab their contents (not their instances) if multiple files are supplied at the same time, thereby avoiding any potential conflicts.

Then again, there are exceptions to that... Office Word, for example, just opens everything as it's own instance, not bothering with tabs at all.  (I suppose this might be adjustable in the options, but if anyone has ever tried to keep Office 12 happy, they'll quickly learn to appreciate their wives more.)

User avatar
nikos
Site Admin
Site Admin
Posts: 14428
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos » 2009 Oct 03, 12:46

$N doesn't automatically insert quotes around the name since you may want to use it in combination with something else. So either use "$N" or $n -- which is the short path so it doesn't have spaces guaranteed

Post Reply