Copy link to clipboard
Copied
I write a jsx to record action.But when i execute the code, the actions panel's state is still recording,so i want to stop recording.Here's the jsx code:
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass(cTID('Actn'));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putName(cTID('ASet'), "culture");
desc1.putReference(cTID('At '), ref2);
var desc2 = new ActionDescriptor();
desc2.putString(cTID('Nm '), "action1");
desc2.putInteger(cTID('FncK'), 0);
desc1.putObject(cTID('Usng'), cTID('Actn'), desc2);
executeAction(sTID('make'), desc1, DialogModes.NO);
My ultimate intention is to convert AM code to action.I don't know if that's possible, or if there's any other way.
Maybe this will help.
Using the ActionMaker object, you can create an Action from any AM code.
It is enough to use a.executeAction() in the script instead of executeAction().
/////////////////////////////////////////////////////////////////////////////////
function ActionMaker(set_name, act_name)
{
try {
this.set_name = set_name;
th
...Copy link to clipboard
Copied
eventually replace this
DialogModes.NO
with this DialogModes.All
Copy link to clipboard
Copied
Sorry,you may not understand what I mean.
Copy link to clipboard
Copied
Do you just want to create an empty action? If so, then in principle it is possible, but difficult. It is not clear why this is necessary.
Copy link to clipboard
Copied
Hi r-bin
Thanks for your reply.I don't want to create an empty ,the jsx file has some AM code after making an action.My ultimate intention is to convert AM code to action.I don't know if that's possible, or if there's any other way.But if i use this way which is making an action through
jsx,how to stop recording mode will be a problem.
Copy link to clipboard
Copied
What advantage or benefit is there in converting AM code into an action compared to recording an action the regular way? Is this meant to be an interactive/variable user driven process controlled from a script?
Perhaps look into xtools for inspiration:
ActionDescriptorToJavascript.jsx
ActionDescriptorToXML.jsx
ActionEvalDemo.jsx
ActionFileBrowser.jsx
ActionFileFromSLCode.jsx
ActionFileFromXML.jsx
ActionFileToJavascript.jsx
ActionFileToXML.jsx
ActionLister.js
ActionSetRunner.js
ActionsPaletteToFiles.jsx
ActionToJavascript.jsx
ActionToXML.jsx
Copy link to clipboard
Copied
Thank you for your reply. It may be helpful to me.
Copy link to clipboard
Copied
My ultimate intention is to convert AM code to action.I don't know if that's possible, or if there's any other way.
Maybe this will help.
Using the ActionMaker object, you can create an Action from any AM code.
It is enough to use a.executeAction() in the script instead of executeAction().
/////////////////////////////////////////////////////////////////////////////////
function ActionMaker(set_name, act_name)
{
try {
this.set_name = set_name;
this.act_name = act_name;
this.data = new Array();
}
catch (e) { alert(e); throw(e); }
}
/////////////////////////////////////////////////////////////////////////////////
ActionMaker.prototype.executeAction = function(event, desc)
{
try
{
this.data.push([event, desc]);
executeAction(event, desc, DialogModes.NO);
}
catch (e) { alert(e); throw(e); }
}
/////////////////////////////////////////////////////////////////////////////////
ActionMaker.prototype.load = function()
{
try {
var file = new File(Folder.temp.fsName + "\\" + "tmp.atn");
var len = this.data.length;
var l0 = (len>>24) & 0xFF;
var l1 = (len>>16) & 0xFF;
var l2 = (len>>8 ) & 0xFF;
var l3 = (len ) & 0xFF;
file.open("w");
file.encoding = "BINARY";
file.write(String.fromCharCode(0,0,0,16)); // dword version
file.write(string_to_bin(this.set_name)); // unicode set name
file.write(String.fromCharCode(0)); // byte set is expanded
file.write(String.fromCharCode(0,0,0,1)); // dword number of actions in action set
file.write(String.fromCharCode(0,0)); // word index of action
file.write(String.fromCharCode(0)); // byte shift key needed for keyboard shortcut
file.write(String.fromCharCode(0)); // byte ctrl key needed for keyboard shortcut
file.write(String.fromCharCode(0,0)); // word color index
file.write(string_to_bin(this.act_name)); // unicode action name
file.write(String.fromCharCode(0)); // byte action is expanded
file.write(String.fromCharCode(l0,l1,l2,l3)); // dword number of items in action
for (var i = 0; i < len; i++)
{
file.write(String.fromCharCode(0)); // byte item is expanded in the Actions palette
file.write(String.fromCharCode(1)); // byte item is enabled
file.write(String.fromCharCode(0)); // byte dialogs should be displayed
file.write(String.fromCharCode(0)); // byte options for displaying dialogs
file.write("long");
file.write(typeIDToCharID(this.data[i][0])); // charID of event
file.write(String.fromCharCode(0,0,0,0)); // dword len and dictionary name
if (this.data[i][1] && this.data[i][1].count)
{
file.write(String.fromCharCode(0xFF,0xFF,0xFF,0xFF)); // long -1 if have descriptor
file.write(this.data[i][1].toStream().substr(4));
}
else
{
file.write(String.fromCharCode(0,0,0,0));
}
}
file.close();
app.load(file);
file.remove();
function string_to_bin(x)
{
try {
var d = new ActionDescriptor();
d.putString(0, x);
return d.toStream().substr(34);
}
catch (e) { alert(e); }
}
}
catch (e) { alert(e); throw(e); }
}
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
var a = new ActionMaker("SET", "ACTION");
// Some AM Code. Use a.executeAction() instead of executeAction()
// ctrl-j
var d = new ActionDescriptor();
a.executeAction(stringIDToTypeID("copyToLayer"), d, DialogModes.NO);
// cteate mask
var d = new ActionDescriptor();
d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
d.putReference(stringIDToTypeID("at"), r);
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("hideAll"));
a.executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
// hide layer
var d = new ActionDescriptor();
var list = new ActionList();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
list.putReference(r);
d.putList(stringIDToTypeID("null"), list);
a.executeAction(stringIDToTypeID("hide"), d, DialogModes.NO);
// show layer
var d = new ActionDescriptor();
var list = new ActionList();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
list.putReference(r);
d.putList(stringIDToTypeID("null"), list);
a.executeAction(stringIDToTypeID("show"), d, DialogModes.NO);
// ctrl-j
var d = new ActionDescriptor();
a.executeAction(stringIDToTypeID("copyToLayer"), d, DialogModes.NO);
// delete mask
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
d.putReference(stringIDToTypeID("null"), r);
a.executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
a.load(); // load action
Copy link to clipboard
Copied
Wow, that's great.Thanks in advance!