当前位置:网站首页>Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
2022-07-05 14:40:00 【Plug in development】
1. Actions in the non loading execution action file
stay PS In scripting , Perform the action by non loading , You don't have to PS Script loading into action manager , You can perform the corresponding action . The code is as follows :
app.bringToFront();
if(typeof jamActions !== 'object')
{
var jamActions = {
};
(function()
{
jamActions.isActionsFile = function(file)
{
return (file.type === '8BAC') || file.name.match( "/ \.atn$ / i");
};
jamActions.isActionsPalette = function(file)
{
return((file.type === '8BPF') && file.name.match( "/ ^Actions Palette$ / i")) || file.name.match( "/ ^Actions Palette.psp$ / i");
};
function readBEInt(file, byteCount)
{
var bytes = file.read(byteCount);
var intValue = 0;
for(var index = 0; index < byteCount; index++)
{
intValue = (intValue << 8) + bytes.charCodeAt(index);
}
return intValue;
}
function readBytes(file, byteCount)
{
return file.read(byteCount);
}
function readByteString(file)
{
var stringLength = readBEInt(file, 4);
return readBytes(file, stringLength);
}
function readUnicodeString(file)
{
var unicodeString = "";
var unicodeLength = readBEInt(file, 4);
for(var index = 0; index < unicodeLength; index++)
{
var unicodeChar = readBEInt(file, 2);
if(unicodeChar !== 0)
{
unicodeString += String.fromCharCode(unicodeChar);
}
}
return unicodeString;
}
function readEventId(file)
{
var eventId = 0;
var eventType = readBytes(file, 4);
switch(eventType)
{
case'TEXT':
eventId = app.stringIDToTypeID(readByteString(file));
break;
case'long':
eventId = app.charIDToTypeID(readBytes(file, 4));
break;
default:
throw new Error("[jamActions readEventId] Unrecognized event type: '" + eventType + "'");
break;
}
return eventId;
}
function skipDouble(file)
{
file.seek(8, 1);
}
function skipDoubles(file, doubleCount)
{
file.seek(doubleCount * 8, 1);
}
function skipInt8(file)
{
file.seek(1, 1);
}
function skipInt16(file)
{
file.seek(2, 1);
}
function skipInt32(file)
{
file.seek(4, 1);
}
function skipInt64(file)
{
file.seek(8, 1);
}
function skipBytes(file, byteCount)
{
file.seek(byteCount, 1);
}
function skipByteString(file)
{
var stringLength = readBEInt(file, 4);
skipBytes(file, stringLength);
}
function skipUnicodeString(file)
{
var unicodeLength = readBEInt(file, 4);
skipBytes(file, unicodeLength * 2);
}
function skipId(file)
{
var idLength = readBEInt(file, 4);
if(idLength)
{
skipBytes(file, idLength);
}
else
{
skipBytes(file, 4);
}
}
function skipClass(file)
{
skipUnicodeString(file);
skipId(file);
}
function skipObject(file)
{
skipClass(file);
var itemCount = readBEInt(file, 4);
for(var itemIndex = 0; itemIndex < itemCount; itemIndex++)
{
skipId(file);
skipItem(file);
}
}
function skipList(file)
{
var itemCount = readBEInt(file, 4);
for(var itemIndex = 0; itemIndex < itemCount; itemIndex++)
{
skipItem(file);
}
}
function skipItem(file)
{
var typeId = readBytes(file, 4);
switch(typeId)
{
case'obj ':
skipReference(file);
break;
case'Objc':
case'GlbO':
skipObject(file);
break;
case'type':
case'GlbC':
skipClass(file);
break;
case'VlLs':
skipList(file);
break;
case'doub':skipDouble(file);break;case'UntF':skipBytes(file,4);skipDouble(file);break;case'TEXT':skipUnicodeString(file);break;case'enum':skipId(file);skipId(file);break;case'long':skipInt32(file);break;case'comp':skipInt64(file);break;case'bool':skipInt8(file);break;case'alis':
skipByteString(file);
break;
case'Pth ':
skipByteString(file);
break;
case'tdta':
skipByteString(file);
break;
case'ObAr':
var objCount = readBEInt(file, 4);
skipClass(file);
var itemCount = readBEInt(file, 4);
for(var itemIndex = 0; itemIndex < itemCount; itemIndex++)
{
skipId(file);
skipInt32(file);
skipInt32(file);
var doublesCount = readBEInt(file, 4);
skipDoubles(file, doublesCount);
}
break;
default:
throw new Error("[jamActions skipItem] Unrecognized item type: '" + typeId + "'");
break;
}
}
function skipReference(file)
{
var itemCount = readBEInt(file, 4);
for(var itemIndex = 0; itemIndex < itemCount; itemIndex++)
{
var formId = readBytes(file, 4);
skipClass(file);
switch(formId)
{
case'Clss':break;case'prop':skipId(file);break;case'Enmr':skipId(file);skipId(file);break;case'rele':skipInt32(file);break;case'Idnt':skipInt32(file);break;case'indx':skipInt32(file);break;case'name':skipUnicodeString(file);
break;
default:
throw new Error("[jamActions skipReference] Unrecognized item form: '" + formId + "'");
break;
}
}
}
jamActions.readActionDescriptor = function(file, insertVersionPrefix)
{
var versionPrefix = "\x00\x00\x00\x10";
var start = file.tell();
if(!insertVersionPrefix)
{
if(file.read(4) === versionPrefix)
{
versionPrefix = "";
}
else
{
throw new Error('[jamActions.readActionDescriptor] Unrecognized version prefix');
}
}
skipObject(file);
var end = file.tell();
file.seek(start, 0);
var stream = versionPrefix + file.read(end - start);
var actionDescriptor = new ActionDescriptor();
actionDescriptor.fromStream(stream);
return actionDescriptor;
};
jamActions.dataFromActionsFile = function(actionsFile, isPalette)
{
var that = this;
function parseActionSet(file)
{
var actionSet = {
};
actionSet.name = localize(readUnicodeString(file));
actionSet.expanded = (readBEInt(file, 1) !== 0);
var actionCount = readBEInt(file, 4);
actionSet.actions = [];
for(var actionIndex = 0; actionIndex < actionCount; actionIndex++)
{
var action = {
};
action.functionKey = readBEInt(file, 2);
action.shiftKey = (readBEInt(file, 1) !== 0);
action.commandKey = (readBEInt(file, 1) !== 0);
action.colorIndex = readBEInt(file, 2);
action.name = localize(readUnicodeString(file));
action.expanded = (readBEInt(file, 1) !== 0);
var commandCount = readBEInt(file, 4);
action.commands = [];
for(var commandIndex = 0; commandIndex < commandCount; commandIndex++)
{
var command = {
};
command.expanded = (readBEInt(file, 1) !== 0);
command.enabled = (readBEInt(file, 1) !== 0);
command.withDialog = (readBEInt(file, 1) !== 0);
command.dialogOptions = readBEInt(file, 1);
command.eventId = readEventId(file);
command.dictionaryName = readByteString(file);
if(readBEInt(file, 4) !== 0)
{
command.actionDescriptor = that.readActionDescriptor(file, true);
}
action.commands.push(command);
}
actionSet.actions.push(action);
}
return actionSet;
}
var file;
if(typeof actionsFile === 'string')
{
file = new File(actionsFile);
}
else if(actionsFile instanceof File)
{
file = actionsFile;
}
else
{
throw new Error('[jamActions.dataFromActionsFile] Invalid argument');
}
var fileData;
if(file.open("r"))
{
try
{
file.encoding = 'BINARY';
var fileVersion = readBEInt(file, 4);
if(fileVersion === 16)
{
fileData = {
};
fileData.version = fileVersion;
if(isPalette)
{
fileData.actionSets = [];
var actionSetCount = readBEInt(file, 4);
for(var actionSetIndex = 0; actionSetIndex < actionSetCount; actionSetIndex++)
{
fileData.actionSets.push(parseActionSet(file));
}
}
else
{
fileData.actionSet = parseActionSet(file);
}
}
else
{
fileData = "Unsupported actions file version: " + fileVersion;
}
}
catch(e)
{
fileData = e.message;
}
finally {
file.close();}
}
else
{
fileData = "Cannot open file";
}
return fileData;
};
jamActions.isLocalPlayCommand = function(command, actionSetName)
{
var localPlayCommand = null;
if(command.eventId === app.stringIDToTypeID("play"))
{
var targetId = app.stringIDToTypeID("target");
if(command.actionDescriptor.hasKey(targetId))
{
var localReference = command.actionDescriptor.getReference(targetId);
do
{
try
{
var desiredClassId = localReference.getDesiredClass();
}
catch(e)
{
break;
}
switch(desiredClassId)
{
case app.stringIDToTypeID("command"):
var localCommandIndex = localReference.getIndex() - 1;
break;
case app.stringIDToTypeID("action"):
var localActionName = localReference.getName();
break;
case app.stringIDToTypeID("actionSet"):
var localActionSetName = localReference.getName();
break;
}
localReference = localReference.getContainer();
}
while(localReference);
}
var continueId = app.stringIDToTypeID("continue");
if(command.actionDescriptor.hasKey(continueId))
{
var localContinue = command.actionDescriptor.getBoolean(continueId);
}
if((typeof localActionSetName !== 'undefined') && (localActionSetName === actionSetName))
{
localPlayCommand = [localActionName, localCommandIndex, localContinue];
}
}
return localPlayCommand;
};
jamActions.determineDialogMode = function(command)
{
var dialogMode;
switch(command.dialogOptions)
{
case 0:
dialogMode = command.withDialog ? DialogModes.ALL : DialogModes.NO;
break;
case 2:
dialogMode = DialogModes.NO;
break;
case 1:
case 3:
dialogMode = DialogModes.ALL;
break;
}
return dialogMode;
}
var globalCommandHandler = null;
jamActions.setCommandHandler = function(commandHandler)
{
globalCommandHandler = commandHandler;
};
jamActions.traverseAction = function(actionSet, actionLocator, fromCommandIndex, continuePlay)
{
function handleCommands(commands)
{
var commandMax = (continuePlay) ? commands.length : fromCommandIndex + 1;
for(var commandIndex = fromCommandIndex; commandIndex < commandMax; commandIndex++)
{
if(globalCommandHandler !== null)
{
globalCommandHandler(commands[commandIndex]);
}
}
}
if(typeof fromCommandIndex === 'undefined')
{
fromCommandIndex = 0;
continuePlay = true;
}
var actions = actionSet.actions;
if(typeof actionLocator === 'string')
{
var actionName = actionLocator;
for(var actionIndex = 0; actionIndex < actions.length; actionIndex++)
{
var action = actions[actionIndex];
if(action.name === actionName)
{
handleCommands(action.commands);
break;
}
}
}
else if(typeof actionLocator === 'number')
{
var actionIndex = actionLocator;
if((actionIndex >= 0) && (actionIndex < actions.length))
{
handleCommands(actions[actionIndex].commands);
}
}
};
}
());
}
//------------------------------------------------------------------------------
if(documents.length)
{
Folder.current = new Folder ("E:/work/CurrentProject/PS66Plugin/ Customer provides / Surface requirements / action /"); //Location of actionset folder.
var actionsFilePath = "66 Custom size .atn"; //Name of atn file.
var ActionName = " Customize 2"; //Name of the action within the action set.
var fileData = jamActions.dataFromActionsFile (actionsFilePath);
if (typeof fileData === 'string')
{
alert (fileData + "\n" + "Actions file: “" + actionsFilePath + "”");
}
else
{
function executeCommand (command, ActionName)
{
if (command.enabled)
{
var dialogMode = jamActions.determineDialogMode (command);
app.executeAction (command.eventId, command.actionDescriptor, dialogMode);
}
}
jamActions.setCommandHandler (executeCommand);
jamActions.traverseAction (fileData.actionSet, ActionName);
};
};
2. The author's message
Reasonable script code can effectively improve work efficiency , Reduce repetitive labor .
边栏推荐
- 循环不变式
- 启牛学堂班主任给的证券账户安全吗?能开户吗?
- Two Bi development, more than 3000 reports? How to do it?
- Mysql database installation tutorial under Linux
- Explain Vue's plan to clean up keepalive cache in time
- 2022年国内正规的期货公司平台有哪些啊?方正中期怎么样?安全可靠吗?
- Run faster with go: use golang to serve machine learning
- 729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」
- TS所有dom元素的类型声明
- ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)
猜你喜欢
用 Go 跑的更快:使用 Golang 为机器学习服务
面试突击62:group by 有哪些注意事项?
Topology可视化绘图引擎
家用电器行业商业供应链协同平台解决方案:供应链系统管理精益化,助推企业智造升级
CPU design related notes
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
【华为机试真题详解】字符统计及重排
Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
一键更改多个文件名字
黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
随机推荐
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Two Bi development, more than 3000 reports? How to do it?
不相交集
Long list optimized virtual scrolling
Detailed explanation of usememo, memo, useref and other relevant hooks
手写promise与async await
危机重重下的企业发展,数字化转型到底是不是企业未来救星
【华为机试真题详解】欢乐的周末
Thymeleaf th:classappend attribute append th:styleappend style append th:data- custom attribute
【華為機試真題詳解】歡樂的周末
有一个强大又好看的,赛过Typora,阿里开发的语雀编辑器
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
浅谈Dataset和Dataloader在加载数据时如何调用到__getitem__()函数
Using tensorboard to visualize the training process in pytoch
CPU设计相关笔记
Isn't it right to put money into the external market? How can we ensure safety?
Postgresql 13 安装
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
开挖财上的证券账户可以吗?安全吗?
CPU design related notes