Metadata: Edit author

With the following code I can set the author of a document without opening the metadata panel:

@disablenosel:files
SetAttr META "author:{dlgstring|Autor:}"

01

But if the document already has an author, it will be removed. Is there any way to display the author's name in the window if it already exists?

I tried:

SetAttr META "author:{dlgstring|Autor:|{author}}" and
SetAttr META "author:{dlgstring|Autor:|{META author}}"

But neither of them work, thanks.

You would need a script to insert any existing entries.

Have you tried the dialog? Seems a lot easier.

 SetAttr META

@dasota in DO13, to append an Author, you can try Find and Replace Metadata.

There are many forms to do that, e.g. using this in the selected files:

FRMeta FIND .* REPLACE "{author};a new author" REGEX PROPERTIES=author

Don't forget to read the main post on the command page first, and check that the file extensions you want to use are defined in `doc_exts' in the script configuration.

@lxp If I need a script for that then I'm lost, I thought it would be a simple thing :grinning:

And yes, I have a button with SetAttr META, but I rarely use it because it generates a large window, and since I normally only modify the Author, I prefer to do it with SetAttr META author.

Thank you so much @lxp!

Hi @errante, thank you very much in advance, I am going to calmly read your work, which I know with certainty will be excellent, I will tell you later, thank you once again!

@errante, I just tried your script and it's actually very good, but I'm looking for a faster and simpler way to modify just the Author.

With the button I have, I apparently solve this situation, since I can establish the author, but I have the drawback that, if the document already has an author, this will be lost because the one I specify will be overwritten over the existing one.

That is why my intention is that, if the document already has an author, it will be displayed so that I can specify the new author after the current author so as not to lose it.

FRMeta FIND .* REPLACE "{author};" REGEX PROPERTIES=author

@dasota have you tried using that? Then you just have to add the new author and press OK (the same as in you previous code).

Yes @errante, I did use that code, but it generates a very large window, much larger than SetAttr META, and that is what I am avoiding :pensive:

I can't understand this fixation with dialogs that you have :smile:.
However...I've made some changes to allow modifying the metadata without showing the dialog. If you want to beta test, I can DM you (and anyone else who's interested) a copy.
Then, after installing the new script, you can use:
FRMeta FIND .* REPLACE "{author};{dlgstring|Autor:}" REGEX PROPERTIES=author NOGUI

It's not overly complicated :slight_smile:

// https://resource.dopus.com/t/metadata-edit-author/48052

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.deselect = false;

    if (!tab.selected_files) return;

    var item = tab.selected_files(0);

    cmd.RunCommand('SetAttr' +
        ' FILE="' + item + '"' +
        ' META "author:{dlgstring|Autor:|' + item.metadata.doc.author + '}"');
}
XML
<?xml version="1.0"?>
<button backcol="none" display="label" hotkey_label="yes" label_pos="right" textcol="none">
	<label>48052</label>
	<tip>metadata-edit-author</tip>
	<icon1>#script</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/metadata-edit-author/48052</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    if (!tab.selected_files) return;</instruction>
		<instruction />
		<instruction>    var item = tab.selected_files(0);</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;SetAttr&apos; +</instruction>
		<instruction>        &apos; FILE=&quot;&apos; + item + &apos;&quot;&apos; +</instruction>
		<instruction>        &apos; META &quot;author:{dlgstring|Autor:|&apos; + item.metadata.doc.author + &apos;}&quot;&apos;);</instruction>
		<instruction>}</instruction>
	</function>
</button>
1 Like

Sorry @errante for making me uncomfortable about things as simple as the size of a window, but I suffer from some illnesses, really from a psychiatrist. :smile:

You can send me your script, yes, it will always be a new opportunity for growth and learning!

Oh @lxp!, I don't know how to thank you so much, with this wonderful script you have made my life easier because I modify many documents every day, thank you very, very much! :star_struck:

Using @lxp's wonderful script, when I select a file that does not have the Author defined, the word "undefined" appears, having to manually delete it to be able to specify the Author. Could someone help me remove this word?

02

I tried to use the following condition, but no success.

var undef = item.metadata.doc.author;

if (undef == "undefined") {
    undef = "";
} else {
    undef = item.metadata.doc.author;

Try if (undef == undefined)

That way nothing happens, the window is not shown

function OnClick(clickData) {
    var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
    cmd.deselect = false;
    if (!tab.selected_files) return;
    var item = tab.selected_files(0);
	var authors = item.metadata.doc.author || "";
    cmd.RunCommand('SetAttr' +
        ' FILE="' + item + '"' +
        ' META "author:{dlgstring|Autor:|' + authors  + '}"');
}

Note that this script as it is, only allows you to modify the first selected file per run.

1 Like

Excellent @errante!, you solved the "undefined" situation for me, now I am going to try to adapt a condition that I inserted to the previous code to see if I can also edit several documents at the same time, I am very happy, thank you so much! :grinning:

Final code, functional for both a single file and several. Note that when multiple files are selected, potential authors will not be shown, and any authors specified will apply to all files equally, removing all previous data.

Eternally grateful to @lxp and @errante :star_struck:

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.deselect = false;

    if (!tab.selected_files) return;

    if (tab.selected_files.count >= 2) {
        cmd.RunCommand('SetAttr META "author:{dlgstring|AUTOR:\n\nNota: Varios archivos seleccionados}"');

    } else {

        var item = tab.selected_files(0);
        var authors = item.metadata.doc.author || "";

        cmd.RunCommand('SetAttr' +
            ' FILE="' + item + '"' +
            ' META "author:{dlgstring|Autor:|' + authors + '}"');
    }
}
1 Like