List Tags and Labels

This script scans the selection for tags and labels. It lists the tags and labels it has found in the log panel and creates two dated text files with them in the source. Folders get scanned recursively. Reading metadata is time-consuming, you will need a bit of patience when scanning many files, especially media files.


// 2022-05-31

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var fsu = DOpus.FSUtil();
    var fso = new ActiveXObject('Scripting.FileSystemObject');
    var tagSet = DOpus.Create().StringSet();
    var labelSet = DOpus.Create().StringSet();
    var currDate = DOpus.Create().Date().Format('D#yyyyMMdd-T#HHmmss');
    cmd.deselect = false;

    function GetTagsFromItem(item) {
        var itemTags = item.metadata.tags;
        if (typeof itemTags == 'undefined') return;
        if (itemTags.count == 0) return;
        for (var e = new Enumerator(itemTags); !e.atEnd(); e.moveNext()) {

    function GetLabelsFromItem(item) {
        var itemLabels = item.Labels();
        if (typeof itemLabels == 'undefined') return;
        if (itemLabels.count == 0) return;
        for (var e = new Enumerator(itemLabels); !e.atEnd(); e.moveNext()) {

    if (tab.selected.count == 0) return;

    cmd.RunCommand('Set UTILITY=otherlog');

    for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        if (item.is_dir) {
            var folderEnum = fsu.ReadDir(item, 'r')
            while (!folderEnum.complete) {
                var folderItem = folderEnum.Next();
                if (folderItem.is_dir) continue;
        } else {

    DOpus.Output('\n... done!');

    var tagsFile = fso.CreateTextFile(tab.path + '\\Tags-' + currDate + '.txt');

    DOpus.Output('\n\n*** Tags:\n');
    if (tagSet.empty) {
    } else {
        for (var e = new Enumerator(tagSet); !e.atEnd(); e.moveNext()) {

    var labelsFile = fso.CreateTextFile(tab.path + '\\Labels-' + currDate + '.txt');

    DOpus.Output('\n\n*** Labels:\n');
    if (labelSet.empty) {
    } else {
        for (var e = new Enumerator(labelSet); !e.atEnd(); e.moveNext()) {
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>List Tags and Labels</label>
	<tip>Scan selection for tags and labels</tip>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction />
		<instruction>// 2022-05-31</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    var fsu = DOpus.FSUtil();</instruction>
		<instruction>    var fso = new ActiveXObject(&apos;Scripting.FileSystemObject&apos;);</instruction>
		<instruction>    var tagSet = DOpus.Create().StringSet();</instruction>
		<instruction>    var labelSet = DOpus.Create().StringSet();</instruction>
		<instruction>    var currDate = DOpus.Create().Date().Format(&apos;D#yyyyMMdd-T#HHmmss&apos;);</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    function GetTagsFromItem(item) {</instruction>
		<instruction>        var itemTags = item.metadata.tags;</instruction>
		<instruction>        if (typeof itemTags == &apos;undefined&apos;) return;</instruction>
		<instruction>        if (itemTags.count == 0) return;</instruction>
		<instruction>        for (var e = new Enumerator(itemTags); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>            tagSet.insert(e.item());</instruction>
		<instruction>        }</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>    function GetLabelsFromItem(item) {</instruction>
		<instruction>        var itemLabels = item.Labels();</instruction>
		<instruction>        if (typeof itemLabels == &apos;undefined&apos;) return;</instruction>
		<instruction>        if (itemLabels.count == 0) return;</instruction>
		<instruction>        for (var e = new Enumerator(itemLabels); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>            labelSet.insert(e.item());</instruction>
		<instruction>        }</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>    if (tab.selected.count == 0) return;</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;Set UTILITY=otherlog&apos;);</instruction>
		<instruction>    DOpus.ClearOutput();</instruction>
		<instruction>    DOpus.Output(&apos;Enumerating...&apos;);</instruction>
		<instruction />
		<instruction>    for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction>        if (item.is_dir) {</instruction>
		<instruction>            var folderEnum = fsu.ReadDir(item, &apos;r&apos;)</instruction>
		<instruction>            while (!folderEnum.complete) {</instruction>
		<instruction>                var folderItem = folderEnum.Next();</instruction>
		<instruction>                if (folderItem.is_dir) continue;</instruction>
		<instruction>                GetTagsFromItem(folderItem);</instruction>
		<instruction>                GetLabelsFromItem(folderItem);</instruction>
		<instruction>            }</instruction>
		<instruction>        } else {</instruction>
		<instruction>            GetTagsFromItem(item);</instruction>
		<instruction>            GetLabelsFromItem(item);</instruction>
		<instruction>        }</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>    DOpus.Output(&apos;\n... done!&apos;);</instruction>
		<instruction />
		<instruction>    var tagsFile = fso.CreateTextFile(tab.path + &apos;\\Tags-&apos; + currDate + &apos;.txt&apos;);</instruction>
		<instruction />
		<instruction>    DOpus.Output(&apos;\n\n*** Tags:\n&apos;);</instruction>
		<instruction>    if (tagSet.empty) {</instruction>
		<instruction>        DOpus.Output(&apos;&lt;&lt;&lt;none&gt;&gt;&gt;&apos;);</instruction>
		<instruction>        tagsFile.WriteLine(&apos;&lt;&lt;&lt;none&gt;&gt;&gt;&apos;);</instruction>
		<instruction>    } else {</instruction>
		<instruction>        for (var e = new Enumerator(tagSet); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>            DOpus.Output(e.item());</instruction>
		<instruction>            tagsFile.WriteLine(e.item());</instruction>
		<instruction>        }</instruction>
		<instruction>    }</instruction>
		<instruction>    tagsFile.Close();</instruction>
		<instruction />
		<instruction>    var labelsFile = fso.CreateTextFile(tab.path + &apos;\\Labels-&apos; + currDate + &apos;.txt&apos;);</instruction>
		<instruction />
		<instruction>    DOpus.Output(&apos;\n\n*** Labels:\n&apos;);</instruction>
		<instruction>    if (labelSet.empty) {</instruction>
		<instruction>        DOpus.Output(&apos;&lt;&lt;&lt;none&gt;&gt;&gt;&apos;);</instruction>
		<instruction>        labelsFile.WriteLine(&apos;&lt;&lt;&lt;none&gt;&gt;&gt;&apos;);</instruction>
		<instruction>    } else {</instruction>
		<instruction>        for (var e = new Enumerator(labelSet); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>            DOpus.Output(e.item());</instruction>
		<instruction>            labelsFile.WriteLine(e.item());</instruction>
		<instruction>        }</instruction>
		<instruction>    }</instruction>
		<instruction>    labelsFile.Close();</instruction>


Thanks for this! Can you point me to a method for having it match the filenames to the labels/tags output? I ran it through a large directory and while it enumerates the tags, I don't know which belongs to which file.

The idea of the script is to be a help in situations like this:

Once you have the tags, you can easily FIND files that carry them:

Additionally, you could modify the script to automatically start a search with the tags it finds.

Tags are also visible as a column and in the metadata pane.

1 Like


If you want an offline list of files and their tags, you can find all files with * (use wildcards) as a tag, then turn on the column which shows them, and use Tools > Print / Export Folder Listing to save it to a text file.

(The CSV or TSV formats are best, as then you don't have to worry about column widths, and you can import them into Excel or Google Sheets. Make sure the Export dialog is set up to include the columns you need as well. Full Path is probably one you would want.)