Question
Script to list all actions
I've got a lot of actions in a lot of actions sets.
There's no easy way to list them - without writing them out by hand. But I'm lazy so I wrote a script to do it:
// Function to get the object value for action sets
function get_action_set_descriptor(index)
{
var r = new ActionReference();
r.putIndex(stringIDToTypeID("actionSet"), index);
return executeActionGet(r);
}
// Function to get the object value for an action within a set
function get_action_descriptor(setIndex, actionIndex)
{
var r = new ActionReference();
r.putIndex(stringIDToTypeID("action"), actionIndex);
r.putIndex(stringIDToTypeID("actionSet"), setIndex);
return executeActionGet(r);
}
// function WRITE FILE (astring, afilename)
// --------------------------------------------------------
function write_it(astring, afilename)
{
if (afilename == undefined) afilename = myFile;
var exportFile = new File(afilename);
exportFile.open("w"); // write destroys
exportFile.writeln(astring);
exportFile.close();
}
// Main function to list all action sets and actions
function list_all_actions()
{
var msg = "";
// Get total number of action sets
var totalSets = 0;
try
{
var desc = get_action_set_descriptor(1);
totalSets = desc.getInteger(stringIDToTypeID("count"));
}
catch (eek)
{
//alert("No action sets found or error retrieving action sets.");
return;
}
for (var i = 1; i <= totalSets; i++)
{
var setDesc = get_action_set_descriptor(i);
var setName = setDesc.getString(stringIDToTypeID("name"));
var numActions = setDesc.getInteger(stringIDToTypeID("numberOfChildren"));
msg += "Action Set: " + setName + " (Total actions: " + numActions + ") + \n"
// alert(msg);
// Loop through actions in the set
for (var j = 1; j <= numActions; j++)
{
var actionDesc = get_action_descriptor(i, j);
var actionName = actionDesc.getString(stringIDToTypeID("name"));
var count = actionDesc.getInteger(stringIDToTypeID("count"));
var itemIndex = actionDesc.getInteger(stringIDToTypeID("itemIndex"));
var numberOfChildren = actionDesc.getInteger(stringIDToTypeID("numberOfChildren"));
var parentName = actionDesc.getString(stringIDToTypeID("parentName"));
var parentIndex = actionDesc.getInteger(stringIDToTypeID("parentIndex"));
var ID = actionDesc.getInteger(stringIDToTypeID("ID"));
var info = "Action: " + actionName +
//"\n count: " + count +
//"\n itemIndex: " + itemIndex +
//"\n numberOfChildren: " + numberOfChildren +
//"\n parentName: " + parentName +
//"\n parentIndex: " + parentIndex +
"\n ID: " + ID;
msg += info + "\n";
// alert(info);
}
}
return msg;
}
// Run the main function
var info = list_all_actions();
write_it (info, "C:\\temp\\actions.txt");
alert("Done!");
Thought it might be useful to someone else other than my future self.
