Script request: Apply tags to selected folders and its subfolders

Discuss and share scripts and script files...
highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

The script part you've posted doesn't contain a closing curling brace
so

Code: Select all

if ($P_TagOptions == "D") {
was executed
regardless if the if clause was true or not. So check that $P_TagOptions
variable

The code I've posted works with that variable set to "D"...
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

So weird! I set Tagoptions to D too. Here it is full code I am using. I got no syntax errors at all
Should I change anything?

Code: Select all

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";

    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
              // Selected folders
        if ($selFolders) {
            $items = formatlist(quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);
        // No selected folders, use folders in <curpath>
        } else {
            $items = formatlist(quicksearch("lbl:** /d", listfolder(<curpath>, , 2, <crlf>)), "sed", <crlf>);
        }
    }

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

I set Tagoptions to D too.
Where? Not in that script...
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

doesn't this

Code: Select all

if ($P_TagOptions == "D") {
what you mean when you said set to D.
I'm totally newbie here, so I think that's it.
What's wrong in my final code? What should I change?

I am so sorry for my lack of knowledge here, but I am trying my best

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

No, that is checking if it was set to "D".

Look at the first script:
"_Initialize"
perm $P_TagOptions;
if (!$P_TagOptions) { $P_TagOptions = "D"; }
That was the original setting

So at least make sure that
if ($P_TagOptions == "D") {
is true by adding a new line after it with

Code: Select all

echo "inside if clause";
and if you see that message box on the next
execution show exactly what is not working
by listing in which folder you are, what is
selected and which subfolders have a label
in that structure...
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

At first I want to know that I am really appreciate your help very much. Many thanks!

Here it is the final code I am using:

Code: Select all

"_Initialize"
    perm $P_TagOptions;
    if (!$P_TagOptions) { $P_TagOptions = "D"; }

"Option: $P_TagOptions"
    if ($P_TagOptions == "D") { $P_TagOptions = "D+F"; }
    elseif ($P_TagOptions == "D+F") { $P_TagOptions = "D"; }
    else { $P_TagOptions = "D"; }
    load "*", "Apply tag", "s";

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";

    $selItems = get("SelectedItemsPathNames");
    // Directories only
      if ($P_TagOptions == "D") {
	  echo "inside if clause";
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
              // Selected folders
        if ($selFolders) {
            $items = formatlist(quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);
        // No selected folders, use folders in <curpath>
        } else {
            $items = formatlist(quicksearch("lbl:** /d", listfolder(<curpath>, , 2, <crlf>)), "sed", <crlf>);
        }
    }

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}
Here are the issues:

1- Every time I run the script it shows a menu and I should click on "Apply tag" to make it run ..... I don't want this menu to appear, just excute the script without choosing any options

I figured that out :lol: I just commented out all Options part. I hope that I didn't make any mistakes here

Code: Select all

// "Option: $P_TagOptions"
    // if ($P_TagOptions == "D") { $P_TagOptions = "D+F"; }
    // elseif ($P_TagOptions == "D+F") { $P_TagOptions = "D"; }
    // else { $P_TagOptions = "D"; }
    // load "*", "Apply tag", "s";

2- In "Current path" scenario, it takes a while to execute the script, during this time whenever I browse any tab or folder it shows "The view is empty"
.... I want a workaround to solve this, like loading popup so I know that something working on background or so.

Again, many thanks

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

Apart from the script command status there aren't any more non-intrusive "I do something now..."
ways, so:

Code: Select all

    $selFolders = GetFoldersOnly(get("SelectedItemsPathNames"), <crlf>, <crlf>);

    if ($selFolders) { // Selected folders
        $items = formatlist(quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);
    } else { // No selected folders, use folders in <curpath>
        msg "Unlabelling folders will now start...";
        $items = formatlist(quicksearch("lbl:** /d", listfolder(<curpath>, , 2, <crlf>)), "sed", <crlf>);
    }

    if ($items) {
        tagitems("label", "", $items);
        msg "Unlabelling finished!";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}
Remove the second msg command if you don't like it...
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

This not what I meant.
I mean that I want to make Xyplorer unresponsive (Can't open folders, or switch to another tabs) while executing the script.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

Not possible (at least not without an external tool, that wouldn't allow mouse clicks while the script is running. Though it's easy to write such a tool)...
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

highend wrote:Not possible (at least not without an external tool, that wouldn't allow mouse clicks while the script is running. Though it's easy to write such a tool)...
I can live with that, no problem!

Another irrelevant question: I want to change the "Sort folder always ascending" setting via a script, is that possible?
I found that I could change "SortFoldersApart" setting and there is no mention about "Sort folder always ascending"

Many, many, and many thanks for your amazing help!

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

Extract the attached .zip file and put the xyLockWhileScriptInProgress.exe anywhere you like.
Adapt the $path (and $exe if necessary) variable in the script...

The tool locks all left mouse button clicks while the script is running and displays a progress bar...
progress.png
progress.png (1.42 KiB) Viewed 2275 times

Code: Select all

    $path = "D:\Users\Highend\Development\AutoHotkey\#NOT UNDER ACTIVE DEVELOPMENT\xyLockWhileScriptInProgress";
    $exe  = "xyLockWhileScriptInProgress.exe";
    $bat = "%TEMP%\~killLock.bat";
    $batContent = <<<>>>
@FOR /F "tokens=1,2,9 delims=," %%P IN ('TASKLIST /NH /V /FO CSV ^| FINDSTR /IL "$exe"') DO (TASKKILL /F /PID %%Q)
>>>;
    writefile($bat, $batContent);

    $selFolders = GetFoldersOnly(get("SelectedItemsPathNames"), <crlf>, <crlf>);

    run """$path\$exe""";
    if ($selFolders) { // Selected folders
        $items = formatlist(quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);
    } else { // No selected folders, use folders in <curpath>
        $items = formatlist(quicksearch("lbl:** /d", listfolder(<curpath>, , 2, <crlf>)), "sed", <crlf>);
    }

    if ($items) {
        tagitems("label", "", $items);
        status "All items unlabelled...", , "ready";
    }
    run """$bat""", , 2, 0;
    delete 0, 0, $bat;

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}

xyLockWhileScriptInProgress.zip
(394.02 KiB) Downloaded 103 times
I want to change the "Sort folder always ascending" setting via a script, is that possible?
It is but it won't get activated until XY is restarted...
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

WOW, That's great :appl: :appl:

I was hoping that it won't need restarting.

Post Reply