xplorer² macros

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

Post Reply
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

xplorer² macros

Post by FrizzleFry »

This a thread to list useful x2 macros.

I'll reserve this original post for comments and links to really nice macros.

Of course the first macros I wrote were to replace several MenuHack user commands.

For example the user command:

C:\tools\x2tools\MenuHack.exe 32786

converts to the macro

command 32786

or

command "copy names"

ps. To see more sample macros click here and then click on the "show sample macros" link (top of the page) to expand the section
Last edited by FrizzleFry on 2018 Feb 10, 07:55, edited 1 time in total.
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

save folder groups

Post by FrizzleFry »

This is a macro that replaces an AutoIT script I have been using for a while. It gets the current folder name plus "-top" or "-bottom" depending on which pane is active and puts it on the text field of the add folder groups dialog. The AutoIt script was based on one of Kilmatead's scripts. The macro was written with help from nikos on this thread.

Code: Select all

# for sanity, limit iterations of get active loop
pop 3
store $3

label getactive

# get active dialog and check if it is the left/top or right/bottom pane 
getfocus
gettext $0
store $1
#message $1

pop "left pane settings"
equal $1
jumpok leftpane
pop "right pane settings"
equal $1
jumpok rightpane

getfocus
sendkey escape
decr $3
jumpok getactive

message "get active loop run three times"
exit

label leftpane
pop "-top"
store $1
goto continue

label rightpane
pop "-bottom"
store $1

label continue

# get name of active folder from address bar
findwnd address
findclass combobox
gettext $2
pop $2
chopstr \-1
addstr $1
store $2

command 33040 # add folder groups
getfocus
settext $2
User avatar
nikos
Site Admin
Site Admin
Posts: 15760
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: xplorer² macros

Post by nikos »

here is one for the weekly backup chore. I have saved a dual bookmark with the left/right (from -> to) folders, called "mine + probook". Then I select all files in the "from" (left) pane, start the copy to dialog. In there I select one of the saved filters (which makes sure temporary files are not copied) called "no object files", then I set the copy options to the saved category "backup" (which basically does "overwrite if newer else skip"). Because I am super cautious I commented out the OK instruction that would start the copy and I do it myself :)

Code: Select all

command "mine + probook"
waitidle
findwnd "left pane"
setfocus
command "select all"
waitidle
command "copy to"
waitwnd
FINDWND filter
FINDCLASS combobox
SELECT "no object" # saved filter
FINDCLASS combobox
SELECT backup
# OK -> uncomment to start copy automatically
note I am using waitidle or waitwnd after each COMMAND instruction (to make sure the command has finished or the dialog appeared, respectively). This isn't compulsory; the macro will work in any case, but if you don't have these explicit waits, you will find that the execution is a bit sluggish, as xplorer2 tries to guess whether a dialog will appear or not. But for simplicity you can omit these waitxxx instructions

at the end of it, xplorer2 will be in dual pane mode, with the desired left/right folders and left pane active; the copy to dialog will look like this:

Image
victor50
Member
Member
Posts: 41
Joined: 2007 Mar 19, 20:36

Re: xplorer² macros

Post by victor50 »

Probably a nobrainer but: Names in Macro's should be English or translated?
User avatar
nikos
Site Admin
Site Admin
Posts: 15760
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: xplorer² macros

Post by nikos »

command and dialog item (window) names should be in whatever language your user interface is. If you have a translation, use the names translated as they appear
victor50
Member
Member
Posts: 41
Joined: 2007 Mar 19, 20:36

Re: xplorer² macros

Post by victor50 »

Ok, tx.
jgt1942
Bronze Member
Bronze Member
Posts: 129
Joined: 2008 Mar 05, 07:21

Re: xplorer² macros

Post by jgt1942 »

OK dumb user here with a few questions regarding Macros. I have created MS Word and Excel macros using the recorder and then sometimes modifying the macro with the MS editor. At this time I'm totally confused about creating macros in X2 and for me the help file was not helpful. I create a lot of MS files (mainly Word and Excel) and in X2 I always have two window panes on the right side of the man window and each has several tabs.

Because I always use X2 to navigate my system if I want to create a new MS file (let's just use Word as my example) I will perform the following steps.
1) Drill down to the desired folder
2) Right-click in the desired window pane
3) Select Explore (item #9 in the list)
4) Select New (item #5)
5) Select the desired MS file type, for word Item #9
6) the test "New Microsoft Word Document.docx" appears, I type my desired name
7) Press enter twice to open the MS Word editor.

I'd like to create a few macros, e.g. one for each of the MS files I most commonly work with but here is where I stumble.
1) I opened the editor (press F12 in X2) it opens with some text already in the window. I have no idea if this is just a sample or I will mess something up if I change the text. My assumption is that I will mess something up.
2) Once I create the macro how do I add it to the row of icons?
3) How do I change the icon and text under the icon?

As you can see I have not made any progress and I'm really confused. Suggestions and detail instructions (dumb user level) would be appreciated. :?
jgt1942
User avatar
nikos
Site Admin
Site Admin
Posts: 15760
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: xplorer² macros

Post by nikos »

for this particular task you need a simple macro like this

Code: Select all

# command unselect # in case there are selected items
getfocus
cmenu "Microsoft word document"
in general macros require reading the documentation and also the demo video.
a macro recorder is coming for the next version
MKairys
Bronze Member
Bronze Member
Posts: 142
Joined: 2003 Apr 15, 15:39
Location: Boulder, Colorado

Re: xplorer² macros

Post by MKairys »

Let me say the biggest obstacle I encountered getting started with macros is that you can't "save" until you "run".
User avatar
nikos
Site Admin
Site Admin
Posts: 15760
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: xplorer² macros

Post by nikos »

the idea is that by running you make sure that what you save does what is intended of it. How is that a hassle?
MKairys
Bronze Member
Bronze Member
Posts: 142
Joined: 2003 Apr 15, 15:39
Location: Boulder, Colorado

Re: xplorer² macros

Post by MKairys »

Well, I type a macro and click Save, which seems quite reasonable and there's no indication that I can't do that. I don't know my macro hasn't been saved until go to Organize and it isn't there and I don't know why. The macro dialog looks like any editing situation, in which I could save at any time, or several times while writing a long macro. I couldn't run it until it it was done but I might want to save my work in the interim.

I'd say if you want to disable save until the macro has been run you should visually disable the Save button.
User avatar
nikos
Site Admin
Site Admin
Posts: 15760
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: xplorer² macros

Post by nikos »

here's a good training for macro-fu! It accepts a list of |-separated strings to search for in filenames, and another |-list of stuff to replace them with, then it calls multiple times the mass rename dialog in "replace filename part" mode. For example

Code: Select all

Microsoft|visual basic|other
ms|vb|0
would search all filenames in the current folder, and replace instances of "Microsoft" with "ms", "visual basic" with vb, etc

Code: Select all

errorstop 0 # resume on errors

# find occurences of the first strings in filenames, and replace them
# substrings separated by | (both for search and replace)
pop "microsoft|visual basic|not there|other"
store $4
pop "ms|vb|0|" # note last one removed (replace with nothing)
store $6
# the same number of substrings should exist both in $4 and $6

# don't use variables 2 and 3 meant for the subroutine
label loop
incr $1 # access one substring at a time
pop "|"
addstr $1 # this makes |#1, isolate the number
chopstr "#-1"
store $5
pop "|"
addstr $5
store $5 # now it is |1, |2 etc
pop $4
chopstr $5
jumperr done # no more strings to process
store $2 # what to search
# message $0
pop $6
chopstr $5
store $3 # what to replace
jsr masren
waitidle
goto loop

label done
exit

# ----------------------------
# rename subroutine: $2 is what to search, $3 what to replace with
# using command IDs instead of names, should work regardless of translation
label masren
COMMAND 32787 #select all
waitidle
COMMAND 32975 #mass rename
POP 0
FINDCLASS ComboBox
SETFOCUS
SELECT 2
FINDWND 1302 # "Preserve extension"
SETCHECK 1
POP 0
FINDCLASS Edit
SETTEXT $2 # what to match
POP 0
FINDCLASS Edit
FINDCLASS Edit
SETTEXT $3 # target
# FINDWND "&preview"
# CLICK
wait 3000 #see what happened, comment it out in the end
OK
ret 0
User avatar
pschroeter
Silver Member
Silver Member
Posts: 283
Joined: 2007 Jan 27, 00:46

Re: xplorer² macros

Post by pschroeter »

nikos wrote: 2018 Sep 14, 05:08 the idea is that by running you make sure that what you save does what is intended of it. How is that a hassle?
It's a bit of a hassle because for years and years I've created macros in Word 2013 (Autohotkey, Quickkeys (Mac)) I've developed the habit of saving my work in progress. You are saying you have to finish the entire macro and run it once before you can save it. Everytime I find I can't save my progress it confuses me.
User avatar
nikos
Site Admin
Site Admin
Posts: 15760
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: xplorer² macros

Post by nikos »

this macro can compare e.g. 2 PDF files as text. Select the 2 PDFs and run the macro. It goes to extract the PLAIN text and compares the TXT files. The technique also works for other documents that support extraction through text filters, e.g. DOC and XLS

make sure you select the 2 PDFs, and copy/paste this code in CUSTOMIZE > MACROS > EDIT MACRO menu command
also make sure you replace my windiff command with whatever diff program you are using

Code: Select all

COMMAND 33175
wait 3000 # finish text extraction

# select (2) text files created recently
COMMAND 32932
FINDWND "cl&ear"
CLICK
POP 0
FINDCLASS Edit
SETTEXT "*.txt"
COMMAND 32925
POP 0
FINDCLASS Edit
SETTEXT "Modified [S]"
# mark created during last minute
FINDWND "&During the previous:"
SETCHECK 1
POP 0
FINDCLASS Edit
FINDCLASS Edit
SETTEXT "1"
POP 0
FINDCLASS ComboBox
FINDCLASS ComboBox
SETFOCUS
SELECT 4
OK
OK

# make sure 2 TXT items are selected
COMMAND 32984 # view selected
getfocus
GETCOUNT $0
# EQUAL 2 #has bug, workaround minus 2
decr $0
decr $0
jumperr diff
message "make sure 2 text documents (eg PDF) are selected"
exit

LABEL diff
# run diff program on selected TXT files
POP 0
FINDCLASS Edit
SETTEXT '> windiff $A' # @@@ replace with your own diff program/path in quotes
COMMAND 33131
Post Reply