[PS脚本] 增量保存

源码

// Incremental Save Script for Photoshop

// Function to add leading zeros
function addLeadingZeros(num, totalLength) {
  var numStr = String(num);
  while (numStr.length < totalLength) {
    numStr = "0" + numStr;
  }
  return numStr;
}

// Function to get the next incremental filename
function getNextFilename(baseName, extension) {
  var folder = app.activeDocument.path;
  var files = folder.getFiles(baseName + "_*.psd");
  var maxNumber = 0;

  for (var i = 0; i < files.length; i++) {
    var file = files[i];
    var name = file.name;
    var match = name.match(/_(\d+)\.psd$/);

    if (match) {
      var number = parseInt(match[1], 10);
      if (number > maxNumber) {
        maxNumber = number;
      }
    }
  }

  var nextNumber = maxNumber + 1;
  var nextNumberStr = addLeadingZeros(nextNumber, 4); // e.g., 0001, 0002, ...

  return baseName + "_" + nextNumberStr + extension;
}

function psReminder2() {
  alert("123");
  // Main script
  //   try {
  //     if (app.documents.length > 0) {
  //       var doc = app.activeDocument;
  //       var baseName = doc.name.replace(/\.[^\.]+$/, ""); // Remove the extension
  //       var extension = ".psd";
  //       var nextFilename = getNextFilename(baseName, extension);
  //       var saveFile = new File(doc.path + "/" + nextFilename);

  //       // Save the document as a PSD with the new filename
  //       var psdSaveOptions = new PhotoshopSaveOptions();
  //       psdSaveOptions.embedColorProfile = true;
  //       psdSaveOptions.alphaChannels = true;

  //       doc.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
  //     } else {
  //       alert("No document is open.");
  //     }
  //   } catch (e) {
  //     alert("Error: " + e.message);
  //   }
}

给TA充电
共{{data.count}}人
人已充电
设计

[ps脚本]使用python通过com调用ps脚本

2024-6-28 19:42:06

归档

【转场周期表】Attention Transition

2022-12-14 3:27:03

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
搜索