Applescript:Photoshop:如何确定图像是否真的打开

Applescript: Photoshop: How to find out whether the image is really open

我们有一个 Photoshop 的自动化工具,使用一个控制应用程序,它调用 Applescripts 控制 Photoshop。

一种情况是我们必须在CameraRAW插件中打开一张RAW图片,然后在Photoshop中打开。这部分是通过使用系统事件的小程序处理的。当该小程序终止时,我们 运行 Photoshop 的处理脚本。

由于有些图片需要很长时间才能打开,因此我们必须确保在脚本可以打开图片之前确实打开了图片运行。 ......这就是我被困的地方。

目前,我正在使用以下代码,该代码旨在等待图像打开("open" 的标准是正确的(并且已手动测试),所以这不是这里的问题)。

    tell application "Adobe Photoshop CC 2015"
        activate

        tell application "System Events"
            tell application process "Photoshop CC"

                --
                display alert "Waiting for Window"
                --

                repeat
                    try
                        set wn to name of window 1 as text
                        try
                            if (wn contains "(RGB/16") then
                                set wn to "image is open: " & wn
                            end if
                        end try
                        if (wn contains "(RGB/16") then
                            display alert "We are there, quitting now…  " & wn
                            exit repeat
                        end if
                    end try
                    delay 1
                end repeat


            end tell
        end tell

        --
        display alert "Ready for process"
        --
-- and here comes the processing code

end tell

我还尝试设置一个变量,该变量被测试为重复的参数,并在满足退出条件时更改。

尝试在重复循环中创建均匀的警报,不会产生任何效果;脚本以无限循环结束。

很可能我错过了明显的东西……所以,我很感激任何有用的提示。

提前致谢。

我认为您的脚本有一些小问题导致了您的问题。

  1. 当我认为您需要 name of document 1 时,您正在使用 name of window 1。使用您的第一个 try 块结构,您没有意识到它实际上在 name of window 1
  2. 上出错
  3. 返回的名称不包含颜色 space 和位数,因此我将结果测试更改为空字符串
  4. 请注意围绕获取文档名称对 try 块的修改
  5. 我认为在这种情况下没有必要使用 "System Events",也没有理由使用它,因此我修改了以下没有使用它的版本。

示例脚本

     tell application "Adobe Photoshop CC 2015" 
        display alert "Waiting for Window"
        repeat
            try
                set wn to name of document 1 as text
            on error
                set wn to ""
            end try

            try
                if wn is not equal to "" then
                    set wn to "image is open: " & wn
                end if
            end try
            if wn is not equal to "" then
                display alert "We are there, quitting now…  " & wn
                exit repeat
            end if
            delay 1
        end repeat

        display alert "Ready for process"

    end tell