使用 Objective-C 获取 Photoshop 的动作列表 [英] Get Photoshop's action list using Objective-C

查看:26
本文介绍了使用 Objective-C 获取 Photoshop 的动作列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C++ 和 Obj-C 为 OSX 编写一个与 Photoshop 交互的应用程序.

I'm writing an application for OSX using C++ and Obj-C that interacts with Photoshop.

我一直在使用带有动态构建的 AppleScripts 的 NSAppleScript 来驱动 Photoshop(是的,这有点可怕......)我希望能够以不同的方式驱动 Photoshop,所以如果有人知道更好的方法,我愿意接受!不幸的是,我无法使用 ScriptingBridge,因为我无法将我的用户绑定到 Leopard.

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.

前几天晚上,当我从 Photoshop 中查询动作列表以显示给我的用户时,出现了一个大问题.显然,Photoshop 的脚本集成并没有将动作列表 API 暴露给 AppleScript.这是我不能使用 ScriptingBridge 的第二个原因.

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.

有谁知道我可以在我的 Obj-C/C++ 程序中访问 Photoshop 的动作列表的方法吗?额外问题:有人知道我可以与 Photoshop 交互的更好方式吗?!

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

推荐答案

不确定如何使用 AppleScript 来实现,但您可以使用 AppleScript 调用此 JavaScript 以返回给定操作列表中的名称.我改编自Image Processor.jsx".

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

这篇关于使用 Objective-C 获取 Photoshop 的动作列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆