Page 1 of 1

Tag counting

Posted: 19 Jul 2022 06:25
by TedL1972
I am looking for an XY script that would do the following:

1) Count the number of instances a tag is applied to documents E.g. 15 documents have the tag "London", 10 docs "Rome" etc.

2) Show the result in descending order with the top item on top such as:

London 150
Paris 75
Rome 61

3) Ability to do the counting for ALL tags no matter in which directory they are and

4) Separately or in addion to the above, to restrict the counting to a specific directory.

Any data if such script already exist?

Re: Tag counting

Posted: 19 Jul 2022 16:10
by highend

Code: Select all

    $path  = "";
    $items = quicksearch("tags:?*", $path);
    $tags  = tagitems("tags", , $items, 1);
    $tags  = regexreplace($tags, "[ ]*?,[ ]+", <crlf>);

    $knownTags = "";
    while (true) {
        if ($tags == "") { break; }
        $firstTag   = gettoken($tags, 1, <crlf>, "t");
        $escTag     = regexreplace($firstTag, "([\\.+*|?(){\[^$])", "\$1");
        $matchTags  = regexmatches($tags, "^" . $escTag . "$", <crlf>);
        $cntTags    = gettoken($matchTags, "count", <crlf>);
        $knownTags .= $cntTags . ":" . $firstTag . <crlf>;
        $tags       = regexreplace($tags, "^" . $escTag . "(\r?\n|$)");
    }
    if ($knownTags) {
        $knownTags = formatlist($knownTags, "ern", <crlf>);
        $knownTags = regexreplace($knownTags, "^(\d+?):(.+?)(?=\r?\n|$)", "$2 $1");
        text $knownTags;
    }
4. Find out what you need to change to get it for all locations...

Re: Tag counting

Posted: 20 Jul 2022 01:06
by TedL1972
Ok, I am editing my previous reply as the code works exactly as I laid it out.

The magic word is "focus". It will work ONLY on the focused pane.

Thank you very much.