SetAttr with {allfilepathdest$}

I'm trying to make a button that uses SetAttr META tags:-unprocessed to remove the tag "unprocessed" from the selected files in both the source and the destination panes of a dual-display lister. The button has the following as its function:

SetAttr META tags:-unprocessed {allfilepathdest$} 
SetAttr META tags:-unprocessed {allfilepath$} 

Unfortunately, this seems to work in the source display only. The files in the destination are unaffected. Check this short video here. Is it possible that SetAttr is unable to operate on files in the destination display?

SetAttr (and most commands) work on the selected files by default, automatically.

Remove the {allfilepath$} and {allfilepathdest$} entirely and it should work.

I'm afraid I don't follow. Why would that work? Removing them would make them do the same as with {allfilepath$} would do. The button removes the tag from the files that are selected in the source display. But I need that button to remove the tags from the selected files in both the source and the destination displays. According to help (Reference / Command Reference / External control codes / Codes for passing filenames) using {allfilepathdest$} should do the job. Removing the codes for passing filenames will leave me with two commands that are exactly the same, and by default, they work on the files selected in the source display.

I can make it work without passing the filename by using the following script:

SetAttr META tags:-unprocessed
Set FOCUS=Toggle 
SetAttr META tags:-unprocessed
Set FOCUS=Toggle

but that source/destination change makes the display flash, and that looks ugly. The code also looks non-pro, like when someone does not know how to do something the proper way, neat and tidy. This being actually the case is beside the point :slight_smile:

Based on the help I'd also expect having the "need" form for both source and destination to disable the button if one of the displays has no files selected, which would be nice.

Don't worry, this is as good as it gets with a command button :slight_smile:

For more grace, use a script:

// https://resource.dopus.com/t/setattr-with-allfilepathdest/39856

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var dtab = clickData.func.desttab;

    cmd.deselect = false;

    cmd.ClearFiles();
    cmd.AddFiles(tab.selected_files);
    if (tab.lister.dual > 0) cmd.AddFiles(dtab.selected_files);
    cmd.RunCommand('SetAttr META tags:-unprocessed');
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="icon" textcol="none">
	<label>39856</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/setattr-with-allfilepathdest/39856</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    var dtab = clickData.func.desttab;</instruction>
		<instruction />
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    cmd.ClearFiles();</instruction>
		<instruction>    cmd.AddFiles(tab.selected_files);</instruction>
		<instruction>    if (tab.lister.dual &gt; 0) cmd.AddFiles(dtab.selected_files);</instruction>
		<instruction>    cmd.RunCommand(&apos;SetAttr META tags:-unprocessed&apos;);</instruction>
		<instruction>}</instruction>
	</function>
</button>
2 Likes

That seems to be fine, @lxp. I'm even surprised I understand what it does. Yet it still feels like a workaround to replace two lines of code that should work with eight lines that do work. It also lacks some of the features the codes for passing filenames provide, eg. disabling the button when no files are selected. I guess that could be emulated too but it would further deviate from the clean-and-short 2-lines solution.

That wouldn't work automatically for files in the destination anyway. You're doing something quite unusual there, so it requires some script code.

I was under the (seemingly false) impression that a button being enabled/disabled depended on files being/not being selected comes from the type of the code for passing filename used, that is, if I use the "need" form, it disables the button if there are no files selected and if I use the "need"-less form, the button is enabled, regardless of the files being selected or not.

I have taken the liberty to quote the relevant parts from the help in bold. This is the description for {filepath$} (the "need" form):

The "need" form of {filepath} (requires at least one selected item in the file list).
Full paths, one at a time, selected items required, long filenames, source file display

The description for {filepath} is the following:

Passes the full path and filename of each selected item. Files are passed one at a time - a command that uses this code will be repeated once for each additional selected item. If no files are selected the command will still be run, passing an empty string for this code.
Full paths, one at a time, selected items not required, long filenames, source file display

(The second quote above is actually not true for buttons. If there are no files selected, the button is disabled, and you cannot run the selected code, as the button won't be clickable. I guess it also depends on the actual command itself, some might not disable the button when there are no files selected).

The descriptions for the destination-side codes are kinda analog, so I thought these would work there as well, namely, if I use a destination-side code, it would disable the button if there are no files selected in the destination display, and if there were both type (side) of codes used, it would require files to be selected on both sides to make the button active.

Unfortunately, these do not work as I expected.

The code @lxp provided uses the function OnClick, which (I guess from the name) only runs when clicked, so it probably can not affect the button's enabled state. Is there an applicable function that I could use to toggle the button state depending on files being selected on both sides?

No, not in general. Automatically disabling buttons is only done for a few simple internal commands, more as a convenience than anything else.

You can use @modifier codes to enable/disable and show/hide buttons based on various conditions when the automatic stuff doesn't work. I don't think you can enable/disable buttons based on what's selected in the destination, though.

That means the button won't do anything if it doesn't have what it needs, but it doesn't visually disable the button (in general). The button just won't do anything when it's clicked if needs something that isn't there when it runs. Most of those details are evaluated when the button is clicked, as it can be fairly expensive. For certain internal commands (e.g. Copy) and for ones you explicitly use modifiers to specify when they should be disabled, the buttons will be visually disabled.

I understand. Script it is then. In this case I'll accept the answer from @lxp.