Page 1 of 1
Automatically Changing Tab Color Based on Directory Path
Posted: 10 May 2024 20:31
by rolander
I'm trying to set up XYplorer to automatically change the background color of the tabs depending on the current directory. For example, I want the tab background color to turn yellow when the active directory is D:\Example_path\ or any subdirectory within it.
Is it possible to implement this directly in XYplorer, perhaps with a script or a setting I might have missed? Any suggestions or guidance on how to achieve this would be greatly appreciated.
Thanks!
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 10 May 2024 20:44
by eil
Scripting can change tab's colours and one of CEA"Changing Location" may trigger such script. Should be possible.
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 05:17
by rolander
I completely forgot to subscribe to this post and I just find out about this answer. Thanks for your help.
So I've tried this:
Configuration / Custom Event Actions / Changing Locations / After browsing a folder
I set the action to Run script and i wrote this:
$path = <curpath>;
if (strpos($path, "T:\") == 1) {
tab("set", , "yellow");
} else {
tab("set", , "default");
}
The idea was to change the tab color to yellow whenever I'm in T:
But i completely failed.
Any ideas why? Or what else could I try?
Thanks!
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 11:41
by RalphM
Did you switch stepping mode on to see where your script fails?
Quite often it is the lack of indentation of the first script line that keeps it from running at all.

Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 12:33
by klownboy
Look at the examples for SC strpos in the help file. The first postion by default is "0" not "1".
strpos(haystack, needle, [start], [matchcase])
start [Defaults to 0] Allows you to specify which position in haystack to start searching. The position returned is still relative to the beginning of haystack.
Code: Select all
if (strpos($path, "T") == "0") {
tab("backcolor","FFFF46");
...
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 13:52
by rolander
Thanks a lot for your help. I've made some progress:
I can make it work like this:
:: $path = <curpath>; if (strpos($path, "T:") == 0) { tab("backcolor", "00FF00"); } else { tab("backcolor", "FF0000"); }
So I have 2 questions:
1. This is probably really basic. The only way I've made it work is by having the script on a single line. If I write it on more than one line, a small window pops up with the lines of my script, and I have to select one of them, and only that line runs. I cannot run the entire script if I write it multi-lined. Step mode activated or deactivated makes no difference. Running the script automatically while browsing or running it from Script / Run Script, also results in the same issue.
2. I've tried this, but the "default" doesn't work. Any ideas on how to revert to default colors?
:: $path = <curpath>; if (strpos($path, "T:") == 0) { tab("backcolor", "F9F900"); tab("textcolor", "000000"); } else { tab("backcolor", "default"); tab("textcolor", "default"); }
Thanks again.
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 14:50
by klownboy
As RalphM mentioned above make sure you use indentations. Don't use the 2 colons unless running scripts from the address bar. Not sure where you are finding
tab("set"...No such command.
Code: Select all
$path = <curpath>;
if (strpos($path, "T") == "0") {
tab("backcolor","FFFF46");
} else {
tab("backcolor","FF0000");
}
Enter this script in the CEA for "Changing locations" as eil mentioned above.
Tools > Configuration > General > Custom Event Actions > Changing location > After painting the file list. Use the drop down for "Action" and change it from "None" to "Run Script". On the same line, click in the area below Script. A scripting dialog box will come up. Enter the above script.
You could obtain the current tab's backcolor with tab("get", "backcolor"); and use that color for the "else" statement, but I haven't tested the result if you from an existing "T" location to another "T" location. You may be better off just resetting the back color as in the first example.
Code: Select all
$path = <curpath>;
$TabBackColor = tab("get", "backcolor");
if (strpos($path, "T") == "0") {
tab("backcolor","FFFF46");
} else {
tab("backcolor", $TabBackColor);
}
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 15:49
by rolander
Thanks a lot. I wasn't aware about the one space indentation in every line.
Now it works perfectly.
I had to change "Default" for "". That resets the colors to it's default.
This is the working one, just in case in the future someone finds it useful:
Code: Select all
$path = <curpath>;
if (strpos($path, "T:") == 0) {
tab("backcolor", "DFDF00");
tab("textcolor", "000000");
} else {
tab("backcolor", "");
tab("textcolor", "");
}
Thanks a lot for your help!
Re: Automatically Changing Tab Color Based on Directory Path
Posted: 20 Jun 2024 17:14
by klownboy
Glad you got it working.
If you're not actually changing the text color when you change the background color (i.e., it stays black, "000000"), you could eliminate the 2 lines for
tab("textcolor"...