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

时间:2016-06-24 13:21:45

标签: applescript photoshop-script

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

有一种情况是我们必须在CameraRAW插件中打开RAW图像,然后在Photoshop中打开它。这部分是通过使用System Events的applet处理的。当该applet终止时,我们运行Photoshop的处理脚本。

由于某些图片需要花费相当多的时间才能打开,因此我们必须确保在脚本运行之前图片是真正打开的。 ......那就是我被困住的地方。

目前,我正在使用以下代码,该代码旨在等待图像打开(“打开”的标准是正确的(并手动测试),因此这不是问题。)

    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

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

尝试在重复循环中创建偶数警报,不会产生任何影响;该脚本以无限循环结束。

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

我认为您的脚本存在一些小问题导致您的问题。

  1. 当我认为您需要name of window 1时,您正在使用name of document 1。在您的第一个try块结构化的情况下,您并未意识到它实际上是在name of window 1上发出错误
  2. 返回的名称不包含颜色空间和位数,因此我将结果测试更改为空字符串
  3. 请注意有关获取文档名称的try块的修改
  4. 我不相信它是必要的,或者有理由使用"系统事件"在这种情况下,所以我在没有它的情况下修改了下面的版本。
  5. 示例脚本

         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
    
相关问题