Get Photoshop's action list using Objective-C

£可爱£侵袭症+ 提交于 2019-12-05 04:02:24

问题


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 way, 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?!


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/3672984/get-photoshops-action-list-using-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!