Tag counting

Discuss and share scripts and script files...
Post Reply
TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Tag counting

Post 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?

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

Re: Tag counting

Post 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...
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tag counting

Post 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.

Post Reply