You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Photoshop脚本中免去手动点击确认按钮的操作

问题说明
  • 预期功能:自动在打开的PS文件中创建写入当前文件名称的文本图层
  • 现存问题:运行脚本时会弹出配置确认窗口,需要手动点击OK才能继续,无法完全自动化
  • 需求:跳过弹窗实现全自动化运行
解决方案

弹窗由代码中的setOptions()函数触发,你已经在setPreferences()中预设了所有所需的配置参数,直接移除main()函数中对setOptions()的调用即可完全跳过弹窗,实现无人工干预自动运行。
如果需要调整文本位置、字体大小、是否包含路径/扩展名等配置,直接修改setPreferences()中/* EDIT STARTS HERE */和/* EDIT ENDS HERE */区间的参数即可。

调整后完整代码

// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop

// bring application forward for double-click events
app.bringToFront();

if ( documents.length > 0 ){prefs = setPreferences(); main()}else{alert("ERROR!!!!!\nSeems we dont have any file open. \nNothing to do. :) \nOpen a file and try again.")}

function setPreferences(){
 var prefs = new Object();
/* EDIT STARTS HERE */
prefs.textFromBottom = 240;
prefs.startOffsetFromLeft = 369;
prefs.fontSize = '40px';
prefs.incPath =true;
prefs.incExt =true;
/* EDIT ENDS HERE */

 prefs.originalDialogMode = app.displayDialogs;prefs.originalRulerUnits = preferences.rulerUnits; app.displayDialogs = DialogModes.ERROR; preferences.rulerUnits = Units.PIXELS;
return prefs;
}

function process(){var origDoc = activeDocument;var fullName = origDoc.name; if(!prefs.incExt){fullName = fullName.replace(/(?:\.[^.]*$|$)/, ''); }if(prefs.incPath){fullName = origDoc.path.toString() + ":: " + fullName;}var myLayerRef = origDoc.artLayers.add();myLayerRef.kind = LayerKind.TEXT;myLayerRef.name = fullName;var myTextRef = myLayerRef.textItem;myTextRef.position = new Array( prefs.startOffsetFromLeft, origDoc.height - prefs.textFromBottom );myTextRef.size = prefs.fontSize; myTextRef.contents = myLayerRef.name;}
function main(){try{process();}catch( e ){/* An error occurred. Restore ruler units, then propagate the error back to the user */preferences.rulerUnits = prefs.originalRulerUnits;app.displayDialogs = prefs.originalDialogMode;throw e;}}

内容的提问来源于stack exchange,提问作者Hugo Avila

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 00:24:04