Open folder by macro / command line

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aml
Posts: 6
Joined: 18 Sep 2012 09:28

Open folder by macro / command line

Post by aml »

Hi,

I have the following scenario. Let's say XYplorer runs as a non-active window. I'm in another application where I have a list of say 100 or 200 frequently used folders, say one is "d:\2\", and many more. I have a macro program that allows for running applications and running files, in the form "run path\xyplorer.exe" and in the form "run abcde" when "abcde" is a file that by Windows, is automatically opened by a given program.

Now back to my question, how to open a folder in XYplorer, with such a macro system, without open XYplorer first, by the macro, and then have to manually do things in XYplorer in order to open the folder.

Let us assume I want to open the folder in the currently opened tab in XYplorer, which means I want to replace the currently shown folder there by the "new" one (it's not new, I just want it now to be shown). Or, alternatively, how to display the "new" folder in a new tab, if that is possible. Or, alternatively, how to displday the "new" folder in any other way within XYplorer, perhaps in pane 1 of 2 visible panes, or in pane 2 of 2 visible panes, the tree being visible, too, or without the tree being visible.

Are there any "command lines" in order to do this, or any scriptlets to launch within XYplorer? If it cannot be done with command lines as above, in the form "run path\xyplorer / attributes or options", how can I run such scriptlets from my macro program to work within XY: where is the interface between external launching XYplorer scripts and those internal XYplorer programming scriptlets?

I cannot program within XYplorer, so I would be thankful to have examples of such XYplorer scriptlets in order to do what I want, to be launched by external macro.

Thank you very much in advance. I hope I made clear what I want. I know how to do scripting in my external macro program, but I cannot learn XYplorer macro language in full, in order to just view a given folder.

Which one of my 3-digit number of folders would be shown, would be determined by a variable, which means my macro program would read the line in my main application, put the line into a variable, then would do the command "run %variable%" or "run path\XYplorer %variable% options" if possible. If that is not possible, the variable would to be transferred from my macro program to the XYplorer scriptlet, which would constitute an additional problem, but perhaps that problem can be overcome.

Probably, what I want to realize is a task that other users would be happy to realize too but don't know to?

Off-topic question: Those smilies here on the left, if I click on one, then click ^c, then click ^v in the text, nothing happens. If I try to dragdrop one into my text with the mouse, nothing happens. How to put one into your text? ("Disable smilies" is not checked.)

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open folder by macro / command line

Post by highend »

Help file - Configuration - Command Line Switches
XYplorer.exe[ /win=min|max|normal][ /ini=myini][ mystartpath]

The order of the switches is not relevant. Only the startup path must be last.
So a "<path>\xyplorer.exe" <the path variable of your macro program in quotes>
should be sufficient.
One of my scripts helped you out? Please donate via Paypal

aml
Posts: 6
Joined: 18 Sep 2012 09:28

Re: Open folder by macro / command line

Post by aml »

Thank you very much, highend, I wasn't aware of that help file page since it's under "configuration", and I was looking not for options one-and-for-all, but for on-the-fly options if I might say.

Works fine, the "new" folder replaces the previous folder in the tab that has currently focus / which had focus when you last left XYplorer, so that is in the unique, first or second pane, according to your current configuration.

So there seem NOT to be any other options for this? I didn't find any, but...

For example, if you have 3 tabs open, 1, 2, 3, with 3 different folders a, b, c, and your active tab is tab 3. Then you do the command line in order to go to folder b (that is currently displayed in tab 2): Well, the command opens the same folder b again, now in tab 3, whilst it would be logical to change the active tab to tab 2 where folder b is already displayed.

Would that be an idea for an XYplorer enhancement?

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open folder by macro / command line

Post by highend »

It depends on what your macro program can do, e.g. if it's able to copy the pathname to the clipboard before it invokes xyplorer, the desired function could be implemented via a (XYplorer) script.
One of my scripts helped you out? Please donate via Paypal

aml
Posts: 6
Joined: 18 Sep 2012 09:28

Re: Open folder by macro / command line

Post by aml »

Thanks for this hint, and of course, AHK can do that. But then, I don't have the slightest idea how to script within XYplorer, incl. the transition between AHK and the XYplorer script.

It would be preferable for the AHK script to trigger the XY script WITHOUT displaying XY yet, since it's not desirable that XY is displayed, together with the "old view", then flashes to the "new view" only. So, if possible, it's more elegant to do the tab selection in XY offscreen, then only display XY.

First, it would be necessary to decide if the user wants to go the path if it is already displayed anywhere (active or non-active pane) (wtl = 2), or if he wants to go to that tab only if it's in the active pane (wtl = 1; wtl is for "where to look").

Independently from this, within XYplorer, there should be a variable indicating if there are 1 or 2 panes displayed currently, let's say XY system variable pc = 1 or 2 (pc stands for "panes count").

Then, if pc = 2, there should be a XY variable saying which of the 2 panes is the active one, currently, so it would be pa (for "pane active") = 1 or 2.

AHK doesn't know this (1 or 2 displayed panes in XY, and if 2, pane 1 or 2 the active one?), and doesn't need to know.

What it must know, is "user wants to jump anyway in case" (wtl = 2) or "user only wants to jump within active pane in case" (wtl = 2). It must transfer this wtl value.

If AHK / XY are able to interact in a way "command attributes", it would be in AHK (pseudocode)

Code: Select all

(A) get current line and put it into clipboard (easy, for the path), then put it into a variable
also for the wtl choice, just a matter of ergonomics within AHK / the main program (AHK has
global variables, so you can trigger a toggle which decides on your current wtl choice)
(send command to trigger XYplorer script) (attribute1: path) (attribute2: 0 or 1 for wtl choice)
If except for the trigger command itself, transaction only is possible by clipboard, the AHK script would be

Code: Select all

(B) get current line and put it into clipboard (easy, the path again)
get the wtl choice and in case, put a "." as first char before the path, as a code sign for (wtl=1)
put all this again into the clipboard
send command to trigger XYplorer script
in the clipboard there would be the path, with or without the leading "."
Then in XYplorer:

In alternative B:

Code: Select all

take the path out of the clipboard and check if first char = "."
if yes, clear that from the path and set wtl to 1
else, set wtl to 0
endif
In alternative A:

Code: Select all

take the path from the first attribute of the command sent from AHK, and take the wtl from the second attribute
Then, for both:

Code: Select all

I assume a generalarray[][][] with pane number, tab number and path, respectively, and pouring all values
from existing, internal XY arrays herein, but you can also use two arrays1[][] and array2[][] with just tab
number and path, respectively, and then you switch from one to the next in case.

if pc = 2 ; (2 displayed panes)
    if wtl = 1 ; (look just in the active pane)
        determine the active pane pa (=1 or =2)
        fill up the array (third case) with the paths in the tabs of pane pa
    else ; (wtl = 2, look in both panes)
        fill up the array (all three cases) with all three values of pane 1 (pane number, tab number, path)
        as before, for pane 2
    endif
else ; (if pc = 1 = 1 displayed pane only)
    determine pa (the one that is displayed, anyway)
    fill up the array with the paths of the unique pane
endif
; this block could be scripted better, in case somebody wants to do the real scripting, I could rearrange it

; then:
found = false
loop: compare the path variable with every generalarray path (third case)
if there is identity:
    show the tab corresponding to that identical path ; e.g.: if arr[2][3][identical path], show tab 3 in pane 2
    variable found = true
    break the loop
endif
endloop

if found = false
    show the path from the single variable (from AHK) within the active tab
    ; alternatively, this "new" path could be shown, by option, within a NEW tab
endif
; EDIT: The showing of XY, at the very end, perhaps by an internal command from within XY,
; or you simply revert back to AHK and run it from there, in its now updated state: NOW ONLY:

Code: Select all

show XY (without flashing from old to new)
So much for the scripts needed. Since I don't know anything of the internals of Xyplorer, of its scripting language, etc., could somebody help me with this? e.g. examples for scriptlets, where to find the necessary interface(s); what internal arrays for tabs are already there in XY and could be accessed by what commands, etc., etc. - i.e. all the help, perhaps by several sources, to GET ME STARTED.

If, with help, I can design the necessary code, I'll be happy to share it with my fellow users.

P.S.: I know I overly complicated the above-mentioned code by options, but you must see that the difficulties do NOT lay in those "complications". If I get the necessary hints for the very basic functionality, that "exceeding functionality" will be easy, there is no additional difficulty in it.

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open folder by macro / command line

Post by highend »

There isn't any communication between AHK and XYplorer. You can only feed XYplorer's scripting engine
with variables that are read either from the clipboard or from a file if you use an external application OR
you're able to control it in a graphical way with AHK commands (which I wouldn't do). The clipboard is
the easiest way.

I wouldn't use a dot as the leading char (because for paths it normally means "relative to").

But anyway...

The following script gets the content of the clipboard and if the line starts with a plus, it will
only compare paths from the active pane, otherwise from both panes with the string (path)
after the plus.

Save the script in your XYplorer's script folder as "SelectOrCreateTab.xys" and invoke XYplorer
from your AHK script with:

Code: Select all

<XYplorer path>\XYplorer.exe /script=SelectOrCreateTab

Code: Select all

/* 19.09.2012, Selects an existing or create a new tab depending on the path in the clipboard
   ::load "<xyscripts>\SelectOrCreateTab.xys";
*/

	$panes = getkey("DP", "General"); // 0 = single pane | 1 = dual pane
	$cb = "<clipboard>";
	$wtl = substr($cb, 0, 1) == "+" ? 1 : 2; // Set wtl variable
	$extPath = replace($cb, "+", "");

	if($panes == 1) { // Dual pane
		if($wtl == 1) { // Just for the active pane
			$tabPathsA = get("Tabs", "|", "a"); // Get paths for all tabs on the active pane
			$numTabsA = gettoken($tabPathsA, "count", "|");
		} else { // Both panes
			$tabPathsA = get("Tabs", "|", "a");
			$numTabsA = gettoken($tabPathsA, "count", "|");
			$tabPathsI = get("Tabs", "|", "i");
			$numTabsI = gettoken($tabPathsI, "count", "|");
		}
	} else { // Single pane
		$tabPathsA = get("Tabs", "|", "a");
		$numTabsA = gettoken($tabPathsA, "count", "|");
	}

	if(isset($tabPathsI) == 1){ // Both panes must be scanned
		while($i <= $numTabsI) {
			$i++;
			if(gettoken($tabPathsI, $i, "|") == $extPath) {
				$tabID = $i;
				$pane = "PI";
				break;
			}
		}
		while($j <= $numTabsA) {
			$j++;
			if(gettoken($tabPathsA, $j, "|") == $extPath) {
				$tabID = $j;
				break;
			}
		}
	} else { // Only a single pane must be scanned
		while($j <= $numTabsA) {
			$j++;
			if(gettoken($tabPathsA, $j, "|") == $extPath) {
				$tabID = $j;
				break;
			}
		}
	}

	// Focus and select the corresponding tab or create a new one
	if(isset($tabID)) {
		if(isset($pane)) { focus $pane; }
		seltab($tabID);
	} else {
		tab("new", $extPath);
	}
One of my scripts helped you out? Please donate via Paypal

aml
Posts: 6
Joined: 18 Sep 2012 09:28

Re: Open folder by macro / command line

Post by aml »

First and all, highend, what should I say? This is highend indeed, tremendously, outrageously kind and helpful: I do NOT remember any such help, or similar, or coming near to such a help, not even half-way: Terrific, splendid! Thank you so much!

On top of this, your script proved to me that scripting in XY is perfectly possible for me - after some trials, that is, made possible by your grandiose help, and which gave me the courage to have some looks into the respective XY help subjects, "Advanced Topics" and then "Scripting", "Scripting Commands Reference" and "Variables". I needed that starting help indeed, and you've given me much much more than just this: I'm overwhelmed!

I own three file managers, XY, X2 and SC, and I must say that up to now, I had used XY the least - I had bought it full price, 85 bucks (= 70(!) plus VAT), and I had been deeply disappointed, especially with respect to the price... well, that was before today (hadn't had web access yesterday)!

Let me say that for the time being, your script does NOT work yet, but I'm sure I'll get to that (and will report here); first, I must becoming acquainted with the syntax and all, and I don't have time for 10 days for doing anything like that, so there will be a little silence in-between, but then, I'll thoroughly check it with the corresponding commands, etc. in the help file, in order to understand your script, and will probably able to debug it, too; I'll report anyway.

As for it is, with both options, "look anywhere" (for example, d:\2 (or d:\2\, but not necessary) from my AHK script put into the clipboard) vs. "look into the active pane only" (+d:\2 in the clipboard, and of course I checked both, clipboard's ok), and independently which XY pane is active, independently if the "wanted" folder is in one of those, if it's only one pane: The script goes to the active tab, hides anything that might have been displayed there, and I get the message, "The system cannot find the path in question." (re-translation from German) - Even when there is only one pane, only one tab, and the "wanted" folder is displayed in the unique tab, it's replaced by the aforementioned message, but never mind, I'll try to debug the script in a fortnight from here, and'll report.
____________________

My AHK trigger script might be of interest for some, so I put the relevant part here, with comments for better understanding what it's meant to do:

Code: Select all

		else if (code = ",") ; Show folder (the first char can be a code = chars that ain't used as the first one, otherwise)
		{
			; I've got an outliner and open other outlines and external files from "."-encoded tree entries,
			; and now (","-encoded) folders, also, by simply pressing "Enter", which
			; (without "." or "," as first char, and originally only) creates sibling items within the tree -
			; I also have separator lines, so I create groups with all my material together, but instead of replicating
			; perhaps dozens of files within my outliner's tree structure, for most external files (that ain't used on a
			; virtually daily basis, I just put (and trigger) the (sub-)folder link (= so many sync probs less):

			zeilentext := substr(zeilentext, 2, instr(zeilentext, "`n") -1) ; first line only and without the ","
			zeilentext := substr(zeilentext, 1, instr(zeilentext, "`r") -1) ; just in case there is no "`n"
			spacepos := instr(zeilentext, " ")
			if spacepos <> 0 ; if space in zeilentext, cut the rest (incl. the space)
			{
				zeilentext := substr(zeilentext, 1, spacepos-1)
			}
			folder := aodrive . zeilentext ; aodrive is "d:\" or  "p:\", depending on the comp I use
			if (filemanager = 2) ; = "SC"
			{
				; without the SC switches /1 and /2 for pane 1/2, but just within the active pane :
				run, "C:\Programme\SpeedProject\SpeedCommander 14\SpeedCommander.exe" %folder%
				; the same could be done for X2 (tried) and certainly for FileBoss also (not tried)
			}
			else ; if filemanager = 1 = "XY"
			{
				if (xywtl = 1) ; global variable "XY where to look" : 1 = only active pane
					clipboard := "+" . folder . "\" ; the "." is for string concatenation in AHK
				else ; xywtl = 2 = both panes
					clipboard := folder . "\" ; ("\" not necessary anyway)
				sleep, 30
				run, C:\Programme\XYplorer\XYplorer.exe /script=SelectOrCreateTab.xys
			}
		}
		else ; Transmit the original "Enter" key (= in AO: "new sibling")	
____________________

Before seeing your incredible script, highend, I had amused myself not with further pseudo-coding, but with design only, of what a really good file manager should be able to do, from in-built functionality, i.e. per command-line. Independently of external scripting, perhaps Donald will be interested in the implementation of such a feature?:

Code: Select all

Per command line - i.e. by external macros, e.g. by AHK - you can display any folder you want in either of the three file managers XY, X2 and SC, and all three can display folders in either the left or the second pane of a two-pane set-up, the active pane becoming the target pane, and the active tab the target tab, in the form (with AHK, "clf" stands for "command line folder", i.e. the folder you wish to display by a command line command)

run, pathfilecommanderexe(XY,X2,SC) clf(withpath)

but only SC lets you choose the target pane, pane 1 or pane 2 (= independently of which is currently the active one, and even both at the same time if you want!), in the form

run, pathSC /l: clf /r anotherclfifyouwant

All three file commanders, though, replace the currently displayed folder in the target pane / target tab with the clf, and most of the time, that's not what you might want, let alone the daily cores of network administrators within corporate environments, hence my feature request.

I propose three switches, in the form

run, pathfilecommanderexe clf clf clf clf... /1or2or3or4 /1or2 /1or2or3

As you can see, I also propose to process more than just 1, or even more than just 2, such clf's, for convenience reasons, the switches, of course, being identical for 2 or several clf's to be processed by one such command line; if you want different switches, you'd simply send 2 or more such command lines in a row.

"In principle" means, "if there is not made an exception by switch C".

"(Default") means, all switches are optional, not mandatory, and there is a default behavior if the switches are not present; but of course, if switch B is present, switch A must be present, and if switch C is present, switches A and B must be present; alternatively, the switches could be made, instead of being in the form of /1 /1 /1, in the form of /a1, /b1, /c1, but I think the /1 /1 /1 form is simpler and more logical, given the order and the defaults of these switches.

A)

1) in principle, display the clf in pane 1

2) in principle, display the clf in pane 2

3) (Default) in principle, display the clf in the active pane

4) EDIT : In principle: If you enter exactly 2 clf's, clf 1/2 is displayed in pane 1/2 (= corresponds to the up to now exclusive SC feature); if switch A is "4" but you enter only 1 clf, in principle it's displayed in pane 1; if you enter more than 2 clf's, in principle the very first one is put into pane 1, and the others are put in pane 2

B)

1) (Default) in principle, display the clf in the ACTIVE tab, i.e. by replacing the currently displayed folder in the target pane determined by switch A, and in case, in the active tab there (which means, if the target pane does not have tabs currently, the currently displayed folder in the target pane is simply replaced by the clf; it is understood, btw, that even a non-active pane can have an active tab, i.e. the tab that was active last time the pane was active. EDIT : It goes without saying that when you enter more than one such clf's, only the first clf will replace an existing display, whilst for the other clf's new tabs will be created.

2) in principle, display the clf in a NEW (additional) tab; also, if there is no tab yet in the target pane, switch from "no tabs" to "tabs" within that pane (which in alternative 1 is not necessary and not wanted, of course)

C)

1) if the clf is already on display anywhere (active or inactive pane, pane 1 or 2), switch there (instead of A and B)

2) (Default = this behavior when the optional switch C is not present:) if the clf is already displayed in the target pane (determined by A), switch there (instead of A or B; but if it is displayed in a non-target pane, follow A and B)

3) don't switch, i.e. display the clf according to A and b even if it's already on display once or multiple times

In the real code for this, switch C would be the outer structure, it seems to me, whilst in the switches, the order above seems to be more natural.
Of course, for some of the switches, I could enhance your code, highend - and will try to do so -, but it goes without saying that internal functionality, with command-line transmission of the switches, by the "normal" but enhanced "display" command, would be much more elegant than to bother the clipboard with that. If Don's interested in the implementation, I'd be happy to refine the programming structure, the structure above being the one for the description of the command only.
Last edited by aml on 20 Sep 2012 21:12, edited 3 times in total.

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open folder by macro / command line

Post by highend »

Don't put paths with a trailing backslash in the clipboard.

Otherwise the (my) script must be changed because it will compare the paths of the tabs (which don't have a backslash) with your external path and ofc this fails (because of the last backslash) and...

Change your AHK line:
run, C:\Programme\XYplorer\XYplorer.exe /script=SelectOrCreateTab.xys

to:
run, C:\Programme\XYplorer\XYplorer.exe /script=SelectOrCreateTab.xys /flg=2

The script works (at least here), I've tested it more than a few times.

If anything goes wrong, insert a "step;" at the beginning of it and you can see how variables are changing and what's happening (and where), when you step through it.
One of my scripts helped you out? Please donate via Paypal

aml
Posts: 6
Joined: 18 Sep 2012 09:28

Re: Open folder by macro / command line

Post by aml »

Unfortunately, not yet.

(with end-"\" deleted of course)

In my line, there is

,2

With the corresponding system variables, AHK will put into the clipboard (here by paste of the original clipboard content):

+d:\2

Trigger line in my AHK script (also by copy and paste) is:

run, C:\Programme\XYplorer\XYplorer.exe /script=SelectOrCreateTab.xys /flg=2

Result, now, with one or two panes (independently if the clf is on display anywhere):

The script goes to the active tab (and does nothing else, whilst before, without the "/flg=2" part, it went there, hid the display and displayed the error message).

Now without the "+" part: Same result, here the original clipboard paste:

d:\2

Since the script works for you, it seems my XY options / settings intervene, but I haven't got the slightest idea which one could cause such a desastrous result - my XY installation is quite normal (all the more so since I had used XY so rarely that I didn't think of tweaking anything).

(Win XP3 German)

(I assume the step hint was for looking into your XY script, not for my AHK script.)

Oh, oh...

(Edit: Wish to add that I just checked, with BeyondCompare - great product even for non-programmers like me! -, that your XY script my AHK script launches, is very well 1:1 identical with the version you so kindly posted here. So it's my XY settings - how could ("factory" or quite normal) settings so deeply affect such a script, or even: they shouldn't do so to begin with!)

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open folder by macro / command line

Post by highend »

I'd say, download my Teamviewer client directly from: http://www.pc-problemhilfe.de/wp-conten ... 110408.exe

and pm me your number (password is preconfigured).

I'd like to see what happens on your system...
One of my scripts helped you out? Please donate via Paypal

aml
Posts: 6
Joined: 18 Sep 2012 09:28

Re: Open folder by macro / command line

Post by aml »

Thank you very much, will do.

EDIT: I just did this: Closed XY. Saved XYplorer.ini under another name. Reopened XY - well, was the trial version now. Looked after my name (no, knew that one) and my XY code (stuffed into some corner of my outliner). Ran my scripts. Same result as with my non-virgin XYplorer.ini. That's another deception hard to bear, but at least, no further need for checking dozens of settings within my original XYplorer.ini as they had perhaps become, just checking within the default or other settings that are done immediately after the very first run incl. entering name and code (stored that also under an alternative name).

Of course, there's always the possibility that the script you kindly shared runs under some special XY settings on YOUR side, but not with those settings set otherwise = by default.

I'm very sorry, I simply don't have the time these days; in October, I'll have time again to dig further into these questions, and I'll be happy to get such great help I'm offered by you. As said, this is simply exceptional. Just a fortnight, I'll get back in touch.

Post Reply