Page 1 of 1

Clone Date [button snippet]

Posted: 25 Dec 2025 00:43
by eil
This button is made solely for my workflow, which is heavily based on Modified date sorting = or more precisely "placing items in proper order one after other" (via changing their M date).
If anybody finds this useful or would wish to modify - fell free. Actually, I'm sharing this mainly just in case, not lose it.

Button works in 2 phases: Empty state(1) and Stored state(2), which have different action for all 3 mouse clicks (Left, Right, Middle).

L1 stores selected item's path in perm var.
L2 clones source Modified date into target's M date +2sec.
IF multiple items selected:
- L1 warns that only one must be selected;
- L2 will show prompt for user to put targets in proper order = top will get source M date +2sec, next +4sec and so on.

R1 shows menu to pick one date from source = date directly stored in perm var.
R2 shows same menu, allowing to choose which One date would be set. The position user picked on R1 is marked bold - to remind what type of date was stored = user can set it to any target's date.
Unlike L2 automatics, R2 provides everything configurable, which is especially useful when multiple items selected:
- prompt to select date Shift (can be negative or left empty);
- IF Shift was set — prompt to additionally select Shift Step which applies to targets after first one, to make consecutive steps in a date change (can be negative or left empty);
-- IF Shift + Shift Step set — user gets prompt to put targets in proper order (for Steps);
-- IF Shift set, but Shift Step left empty — all targets get same date Shift;
-- IF both left empty — all targets get same date as source.

Extra combination L1 + R2 works similar to R2 described above, but menu gets additional choice to clone All 3 dates from source.(with same prompt
options)
3 dates menu.png
3 dates menu.png (4.77 KiB) Viewed 385 times

M1 shows reminder with short hints of actions description.
M2 show menu with 2 self-explanatory lines: Clear date stored and View date stored.

Icons for button.
clondate(24,512).zip
(40.38 KiB) Downloaded 16 times
Snippet:

Code: Select all

Snip: CTB 1
  XYplorer 26.80.0410, 25.12.2025 3:07:16
Action
  NewUserButton
Name
  Clone Date
Icon
  clonedate.png
ScriptL
  $itemCheck = strpos("<selitems |>", "|");    // -1= single item; else multiple
    perm $srcDate;
  
  //// Date is clear, 1 run
    if ($srcDate == "") {
      if ($itemCheck != "-1") {
        msg "One item must be selected!";
      } else {
      $srcDate = <curitem>; 
      trayballoon $srcDate;
      ctbstate(1);
      //ctbicon("clonedate.png*#6C6C96");
      status "Date picked.", , "progress";
      }
    } else {
  
  //// Date is picked, 2 run
      if (strpos($srcDate, "<crlf>") != "-1") { 
        msg "Direct date was picked.<br>Use R-menu to set one.", , , "! Error !";
        break;
      } 
      $dateType = "m";
      //$Shift = input("Enter date Shift value.", "Format:: number_space_term<crlf>Number:: digits, can be negative.<crlf>Term::  s=sec  n=min  h=hour  d=day  w=week  m=month  y=year<crlf><crlf>Make empty or Cansel for no Shift = Clone date.", "2 s", , "", , , "2 s|-2 s");
      $Shift = "2 s";
  
  // IF Shift was set/not empty = propose consecutive shift+steps
      if (($Shift != "") && ($itemCheck != -1)) {
        //$ShiftStep = input("Consecutive date Shift?.", "Each consecutive item's date = Shift+Step.<crlf>Step can be negative.<crlf><crlf>Keep empty or Cansel for no consecutive Steps.<crlf>[Only main Shift would be used for all items.]", "", , "", , , "1|2|3|-1|-2|-3");
        $ShiftStep = "2";
      }
  
  // IF Shift was set/not empty + consecutive steps added
      if (($Shift != "") && ($itemCheck != -1) && ($ShiftStep != "")) {
          $trgtList = inputselect("Re-Order items for date change::<crlf>Top = +1 date shift.<crlf>Bot = +Max date shift.", "<selitems |>", ,1+2+16+512+32768);
  
          $ShiftNumb = gettoken($Shift, 1, " "); 
          $ShiftTerm = gettoken($Shift, 2, " "); 
          foreach($item, $trgtList, "|") {
            timestamp $dateType, "$srcDate", $item, "*", $Shift; 
            $ShiftNumb = $ShiftNumb + $ShiftStep;
            $Shift = $ShiftNumb . " " . $ShiftTerm;
          }
      } else {
  
  // Similar shift/date for all
          $trgtList = "<selitems |>";  
          timestamp "m", "$srcDate", $trgtList, "*", $Shift; 
        }
      unset $srcDate;
      ctbstate(0);
      //ctbicon("clonedate.png");
      status "Date cloned.", , "ready";
    }
ScriptR
  $itemCheck = strpos("<selitems |>", "|");    // -1= single item; else multiple
    perm $srcDate;
  
    $iconG = "data:png:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAfADXAABNp5UEAAAACXBIWXMAAC4jAAA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GENF3iE+rQLBgAk2+DrE+lIAGAlQz7fM1XJLv1VP96nNmieZ9wh0tNd1s6AgS4Xc95CpsMcklDVx9y18A9t/8uy9C2o6vDguq7Og2YiAgBG0kiaqjoOwKxks5Idd2OMyh65v3+3BAC11p/Q8tD2vfzj4tSaUmvt+JNduG2BZLfCQSXyeJFGU5AXWxf+zhuiQ4Y08pod9gAAAABJRU5ErkJggg==";
    $iconB = "data:png:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAfADXAABNp5UEAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH6QwCFSIW2+1XigAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAC4SURBVDjLlVPBDYQwDHNQ12CPLsSNkQdjtAvdHh4kfOgRSMuBJSSD0yZxguCAOS6I6OrTLhgAkPTB16enIwFALobv50iai4X0V729Tz5onmfcoaenu6weI10u5ryFTM0cklDVxzy08A++/2VZzi2o6vDguq7BAzcRAQAjaSRNVQMHYLmY5WKBhzH2yh65v3+3BAC11p/geQ+t/HZx8qbUWk/8yS7ctkDytMKdSuTxIo2mIC+2rvs7b4zYiQVoPdOqAAAAAElFTkSuQmCC";
    
  //// Date is clear, 1 run
    if ($srcDate == "") {
      if ($itemCheck != "-1") {
        msg "One item must be selected!";
        break;
      } else {
        $dateType = popupmenu("Copy only Created;c;$iconG|Copy only Modified;m;$iconY|Copy only Accessed;a;$iconR", , , , , , , , "None");
        if ($dateType == "None") { break;}
        $srcDate = filetime(<curitem>, $dateType);
        $srcDate = $srcDate . <crlf> . $dateType;
      }
      trayballoon $srcDate;
      ctbstate(1);
      //ctbicon("clonedate.png*#6C6C96");
      status "Date picked.", , "progress";
    } else {
  
  //// Date is picked, 2 run
  // Mark menu item by dateType previously selected
      switch (gettoken($srcDate, 2, <crlf>)) {
        case "c":
          $markC = 1;
          break;
        case "m":
          $markM = 1;
          break;
        case "a":
          $markA = 1;
          break;
        default:
          $markCMA = 1;
          break;
      }
  // IF direct date was picked
      if (strpos($srcDate, "\") == "-1") {
        $dateType = popupmenu("Set only Created;c;$iconG;$markC|Set only Modified;m;$iconY;$markM|Set only Accessed;a;$iconR;$markA", , , , , , , , "None");
      } else {
  // IF item was picked (+3 dates)
        $dateType = popupmenu("Set only Created;c;$iconG;$markC|Set only Modified;m;$iconY;$markM|Set only Accessed;a;$iconR;$markA|-|Set all 3 Dates;cma;$iconB;$markCMA", , , , , , , , "None");
      }
      if ($dateType == "None") { break;}
  
      $Shift = input("Enter date Shift value.", "Format:: number_space_term<crlf>Number:: digits, can be negative.<crlf>Term::  s=sec  n=min  h=hour  d=day  w=week  m=month  y=year<crlf><crlf>Make empty or Cansel for no Shift = Clone date.", "2 s", , "", , , "2 s|-2 s");
  
  // IF Shift was set/not empty = propose consecutive shift+steps
      if (($Shift != "") && ($itemCheck != -1)) {
        $ShiftStep = input("Consecutive date Shift?.", "Each consecutive item's date = Shift+Step.<crlf>Step can be negative.<crlf><crlf>Keep empty or Cansel for no consecutive Steps.<crlf>[Only main Shift would be used for all items.]", "", , "", , , "1|2|3|-1|-2|-3");
      }
  
  // IF Shift was set/not empty + consecutive steps added
      if (($Shift != "") && ($itemCheck != -1) && ($ShiftStep != "")) {
          $trgtList = inputselect("Re-Order items for date change::<crlf>Top = +1 date shift.<crlf>Bot = +Max date shift.", "<selitems |>", ,1+2+16+512+32768);
  
          $ShiftNumb = gettoken($Shift, 1, " "); 
          $ShiftTerm = gettoken($Shift, 2, " "); 
          foreach($item, $trgtList, "|") {
            timestamp $dateType, gettoken($srcDate, 1, "<crlf>"), $item, "*", $Shift; 
            $ShiftNumb = $ShiftNumb + $ShiftStep;
            $Shift = $ShiftNumb . " " . $ShiftTerm;
          }
      } else {
  
  // Similar shift/similar date for all items
          $trgtList = "<selitems |>";  
          timestamp $dateType , gettoken($srcDate, 1, "<clrf>"), $trgtList, "*", $Shift; 
      }
      unset $srcDate;
      ctbstate(0);
      //ctbicon("clonedate.png");
      status "Date cloned.", , "ready";
    }
ScriptM
  if ((isset($srcDate) == 1) && ($srcDate != "")) {
    $menu = popupmenu("Clean date variable;clean;:del|-|Show date variable;show;:shellprops", , , , , , , , "None");
    switch ($menu) {
      case "clean":
        unset $srcDate;
        ctbstate(0);
        //ctbicon("clonedate.png");
        status "Date cleared.", , "ready";
        break;
      case "show":
        echo $srcDate, "Variable contain:";
        break;
      case "None": break;
      default: "None";
    }  
   } else {
     msg "L1 = Pick item (path)<br>L2 = Set Modified date<br><br>R1 = Pick single date<br>R2 = Set single date<br><br>L1+R2 = Set all 3 dates<br><br>M2 = Clear date variable<br>M2 = View date variable", , , "Information";
   }
FireClick
  0