![]() |
XYplorer Scripting, introduced with version 7.00, can truly be seen as the ultimate in file management efficiency. Roll your own custom commands, combine them to scripts, wrap them in an XY Script file (XYS), or a User-Defined Command, and trigger them by just a click or a keystroke. Can't get any better? It can! Share scripts with colleagues, or download them from the internet: Just drop a script file into your app folder and fresh plug-in commands are at your finger tips. |
Without doubt, scripting is an advanced feature that only pays off if you take the time to dive into it and explore the ways and possibilities. However, you will eventually find out that it ain't rocket science at all.
Before we dig deeper, here are some of the truly wonderful things Scripting can do for you:
![]() |
To get you started let's do some easy warm-ups:
Select menu Scripting | Try Script...
Paste msg "Hello world!" into the edit box.
Click OK.
You should see a "Hello world!" message box now. Well done, you just wrote your first XYplorer script! |
Okay, now for something a little bit more interesting: Try msg "%temp%". You should see a message box that displays your TEMP path. %temp% is a standard Windows environment variable.
Try msg "XYplorer.exe runs from <xypath>". <xypath> is a native XYplorer variable that resolves to XYplorer's application path.
Try msg "Press OK to copy the time!"; copytext "<date hh:nn:ss>". When the message box is OKed, the second command copytext is immediately executed and the current time is copied to the clipboard.
Try $a = "<curpath>"; msg $a. You should see a message box displaying the current path. First the variable $a is set to the current path, then it is used in the msg command.
Try $a = "Year " . "<date yyyy>"; msg $a. You should see a message box displaying "Year 2008" (or whatever the year might be when you try this). First the variable $a is set to two strings, one literal and one variable, concatenated by a dot, then it is used in the msg command.
What you have seen so far from XY scripting is: There are commands consisting of a function name like msg or copytext, and arguments that can contain literals like "Hello!", and variables like %temp% (environment), <curpath> (XYplorer), or $a (user-defined).
An argument can have more than one part. The parts are concatenated by dots ( . ).
A command can have more than one argument. The arguments are separated by commas ( , ).
A script can have more than one command. The commands are separated by semi-colons ( ; ).
|
Of course, the Try Script... dialog is just for playing and debugging. For everyday usage we need something better than that. | |
Let's start with Quick Scripting: Ensure that "Quick Scripting" in Configuration | Advanced is on.
Now paste ::msg "Hello world!" into the Address Bar and press Enter. You should see a "Hello world!" message box.
As you see, Quick Scripting means: Scripts, when prefixed with "::", can be executed directly (i.e. quickly) through any interface in XYplorer that can process locations: Address Bar, Go To, Favorites, Catalog etc. This gives you a lot of choices for usage and storage of scripts. |
Now, for mouse users, the Catalog is a very good place for scripts. Using the "::" prefix, scripts can be simply entered into the Location field of a catalog item. They are executed on a single click. For example: Add a new category "Scripts" and add a new item to it.
Set item's Location field to ::#1026 (screenshot) and save it. The icon turns into the script symbol.
Now click the item. The Find Files tab on the Info Panel is opened, all search filters are reset, and the cursor is placed into the Name field. Nice!
| |
But how did this work? And what is #1026? In XYplorer almost every function has a fixed number, the function ID, by which it can be referred to in a script. ID #1026 happens to refer to "Miscellaneous / Find Files / Open Find Files and Reset". Open the Customize Keyboard Shortcuts dialog (menu Tools) and find this function in category Miscellaneous. At the bottom of the dialog you'll see a button showing the function's ID (screenshot). Clicking this button will copy the function's ID to the clipboard, making it easy to use it in a script. Here's another simple but useful script. You could place it e.g. into the Favorite Folders menu by adding it via List Management (screenshot). ::rename "b", "*-<datem yyyymmdd>"
This little script will rename all currently selected items by appending the current date.
Of course, also longer scripts fit in a Catalog item or other location place, for example (screenshot): ::goto "Desktop|"; sortby "m", "d"; sel 1; focus "List";
This script goes to the Desktop folder (ensuring that the listing is unfiltered), sorts the list by date modified (descending), selects the first item, and moves the focus to the list.
|
![]() |
Now, for passionate keyboarders, there are UDCs (User-Defined Commands). Using the "::" prefix, scripts can be simply entered into the Location field of a UDC Go To item (screenshot), which then can be assigned a keyboard shortcut to.
For example: Click menu User | Manage Commands...
Select the category Go To, and click the New button.
Enter ::text "<clipboard>" into the Location field.
Assign a keyboard shortcut, say Ctrl+Alt+3.
Click Apply and OK.
Now press Ctrl+Alt+3. You should see a small window displaying the current textual contents of the clipboard. |
![]() |
Of course, you don't have to abuse the UDC Go To for scripts. There's also the UDC Run Script which accepts scripts without a prefixed "::", e.g. text "<clipboard>". Run Script can also handle more advanced stuff like multi-line scripts (see image on the left), and multi-scripts, the rules and possibilities of which will be further explained below under "XYplorer Script Files". Here's just an appetizing preview: goto "Desktop|"; // sort by modified date, descending sortby "m", "d"; // select first sel 1; focus "List"; |
What you have learned in this section about XY scripting is: Scripts, when prefixed with "::", can be executed from anywhere where you also could enter a location term. This could be a Catalog item, or also e.g. a Favorite Folder
You can execute almost any function in XY in a script by referring to its function ID. E.g. #230 will pop up the submenu "New" of menu Edit.
|
![]() |
Suppose you have an older script #230, and you forgot what #230 refers to. What now? Very simple, enter stepping mode:
Open the Scripting menu and select "Step Through Scripts".
Now execute your mysterious script.
|
A small dialog will pop up and tell you what is about to happen (screenshot). You can now decide whether to execute the command, or skip it, or cancel the whole script. In stepping mode you are on the safe side. It is highly recommended when writing or debugging scripts! |
There's also a toolbar button for toggling the stepping mode. When pressed (stepping is ON) its color changes to red to make the current state very clear. |
![]() |
Here we are talking popup menus that are user-defined by a text file. Let's make one:
// some little test scripts "Go to C:\" goto "C:\" "Go to System Folder" goto "%winsysdir%" "Go to XYplorer Folder" goto "<xypath>"
A script file is basically a library of scripts. It is nothing more than a simple text file, which can contain one or more scripts. You will be able to either call one of those scripts directly, or simply load the entire file. In such case, XY will create a menu based on the contained scripts in that file and pop it up, allowing you to choose which script to execute.
The syntax for the scripts themselves within script files is exactly the same as for scripts anywhere else in XY since this is just another way to store and execute scripts.
To Load a Script File do one of the following:
The existence of a command load, of course, means that one script file can load another. You will get an idea of the potential of scripting by now...
By using labels you can execute a script inside a file directly, avoiding the popup menu. The label is attached to the caption, separated by " : " (space-colon-space). For example:
// some little test scripts, using labels "Go to C:\ : croot" goto "C:\" "Go to System Folder : system" goto "%winsysdir%" "Go to XYplorer Folder : xy" goto "<xypath>"
If the above is saved to a file called "test.xys" in application data path then the following command will directly bring you to the System folder: load "test.xys", "system".
Hidden scripts can be executed but are not shown in the script file's popup menu. To hide a script simply prefix an underscore to the caption or label (a hidden script does not need a caption anyway).
For example, create a script file "date.xys" in application data path with the following contents:
// this is in script file "date.xys" "_date" msg "<date yyyy-mm-dd>" "_time" msg "<date hh:nn:ss>" "Show Date : date" sub _date; "Show Date && Time : datetime" sub _date; sub _time
Now execute the script load "date.xys". The popup menu will show only two of the four contained scripts. Select either and see what happens. |
![]() |
Now run the script load "date.xys", "date". The script with the label "date" will be executed directly. It has only one command: sub "_date";. The sub command is a special command to call a script inside the same script file. In this case the hidden script with the label "_date" is called and executed. Its command msg "<date yyyy-mm-dd>" produces the message box showing the current date. |
![]() |
Advancing in script writing, you will soon feel the need for variables. XYplorer allows you to define and use as many variables as you want, using a number of commands like set, input, replace, etc. The script $a = "Hi!"; msg $a; will define a new variable $a and assign the string "Hi!" (without the quotes) to it; then a message box will display "Hi!".
Variables are resolved wherever they are found in the arguments of all subsequent commands of the script, even if they are found inside quoted strings; for example:
$name = "Ted"; msg "Hi, I'm uncle $name!";
will display the message "Hi, I'm uncle Ted!".
Variables have to conform to the following rules:
Variable names are case-sensitive. The scope and lifetime of a variable begins and ends with the script where it has been defined.
Sample output:
FindTemplates | [DIR] | 2008-10-15 08:17:33 |
NewItems | [DIR] | 2008-10-15 08:17:33 |
Scripts | [DIR] | 2008-10-15 08:17:33 |
catalog.dat | 4.612 bytes | 2008-11-04 10:33:34 |
CatalogDefault.dat | 4.612 bytes | 2008-10-15 11:00:00 |
fvs.dat | 92 bytes | 2008-11-04 10:33:34 |
ks.dat | 8.224 bytes | 2008-11-04 10:33:34 |
LicenseXY.txt | 4.120 bytes | 2008-10-15 11:00:00 |
ReadmeXY.txt | 5.535 bytes | 2008-10-15 11:00:00 |
TipOfTheDay.htm | 20.120 bytes | 2008-10-16 07:51:58 |
udc.dat | 36 bytes | 2008-11-04 10:33:34 |
Uninstall.exe | 69.872 bytes | 2008-11-04 10:32:53 |
XYplorer.cnt | 1.244 bytes | 2008-10-15 11:00:00 |
XYplorer.exe | 3.096.576 bytes | 2008-11-04 10:32:18 |
XYplorer.hlp | 293.040 bytes | 2008-10-15 11:00:00 |
XYplorer.ini | 25.038 bytes | 2008-11-04 10:33:34 |
XYplorer.url | 49 bytes | 2008-11-04 10:32:53 |
For a complete reference of all scripting commands see the Help file.
Here is a places where you can find free scripts to use and learn: