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!
Automatically Changing Tab Color Based on Directory Path
Re: Automatically Changing Tab Color Based on Directory Path
Scripting can change tab's colours and one of CEA"Changing Location" may trigger such script. Should be possible.
Win 7 SP1 x64 100% 1366x768|1900x1080
Re: Automatically Changing Tab Color Based on Directory Path
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!
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
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.
Quite often it is the lack of indentation of the first script line that keeps it from running at all.
Ralph 
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Automatically Changing Tab Color Based on Directory Path
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
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.
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.
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Automatically Changing Tab Color Based on Directory Path
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 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.
tab("set"...No such command.Code: Select all
$path = <curpath>;
if (strpos($path, "T") == "0") {
tab("backcolor","FFFF46");
} else {
tab("backcolor","FF0000");
}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
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:
Thanks a lot for your help!
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", "");
}
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Automatically Changing Tab Color Based on Directory Path
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
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"...
XYplorer Beta Club