Get Photoshop's action list using Objective-C

北城余情 提交于 2019-12-03 21:43:18

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.

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