Get Photoshop's action list using Objective-C
I'm writing an application for OSX using C++ and Obj-C that interacts with Photoshop.
I've been using NSAppleScript
with dynamically built AppleScripts to drive Photoshop (yes, it's a little scary...) I would love to be able to drive Photoshop a different wa开发者_运维百科y, so if anyone knows a better way, I'm open to it! Unfortunately, I can't use ScriptingBridge
as I can't tie my users to Leopard.
The big problem came just the other night when I went to query the action list from Photoshop to display to my users. Apparently, Photoshop's scripting integration doesn't expose the action list APIs to AppleScript. Which is a second reason why I can't use ScriptingBridge
.
Does anyone know a way I can access Photoshop's action list in my Obj-C/C++ program? Bonus question: does anyone know a better way I could be interacting with Photoshop?!
Not sure how to do it with AppleScript but you can call this JavaScript using AppleScript to return the names in a given action list. I adapted this from "Image Processor.jsx".
function GetActionList(folderName)
{
var setCounter = 1;
var actions = '';
var actionName;
gClassActionSet = charIDToTypeID( 'ASet' );
gClassAction = charIDToTypeID( 'Actn' );
gKeyName = charIDToTypeID( 'Nm ' );
gKeyNumberOfChildren = charIDToTypeID( 'NmbC' );
while ( true )
{
var ref = new ActionReference();
ref.putIndex( gClassActionSet, setCounter );
var desc = undefined;
try { desc = executeActionGet( ref ); }
catch( e ) { break; }
actionName = desc.getString( gKeyName );
var numberChildren = 0;
if ( desc.hasKey( gKeyNumberOfChildren ) )
numberChildren = desc.getInteger( gKeyNumberOfChildren );
if ( numberChildren )
{
if(actionName == folderName)
{
for ( var i = 1; i <= numberChildren; i++ )
{
var ref = new ActionReference();
ref.putIndex( gClassAction, i );
ref.putIndex( gClassActionSet, setCounter );
var desc = undefined;
desc = executeActionGet( ref );
if( desc.hasKey( gKeyName ) )
{
if(actions.length > 0)
actions = actions + ',' + desc.getString( gKeyName );
else
actions = desc.getString( gKeyName );
}
}
break;
}
}
setCounter++;
}
return actions;
}
I don't think there is a "better" way to interact with photoshop. Applescript is the way. That's what it was built for. Regarding getting a list of the actions, my only suggestion would be that the actions must be located in a folder somewhere on the hard drive. Isn't each action a separate file? I'm not sure about that but that would be an approach worth looking into. Maybe you can figure out which folders they reside in, and get the action's file names and basically recreate the hierarchy of the actions menu by querying the folder structure.
精彩评论