2016-06-24 37 views
0

我們有一個Photoshop自動化工具,使用一個控制應用程序,它調用Applescripts來控制Photoshop。Applescript:Photoshop:如何找出圖像是否真的開放

一種情況是,我們必須在CameraRAW插件中打開RAW圖像,然後在Photoshop中打開它。通過使用系統事件的小程序處理這部分。當該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 

我也嘗試設置一個變量,它作爲重複的參數進行測試,並在退出條件滿足時進行更改。

試圖在重複循環內創建均衡警報,不會產生任何影響;該腳本以無限循環結束。

這很可能是我錯過了顯而易見的...所以,我很感激任何有幫助的提示。

在此先感謝。

回答

1

我認爲你的腳本有一些小問題會導致你的問題。

  1. 如果我認爲您需要name of document 1,您正在使用name of window 1。您的第一個try塊的結構,因爲它是你沒有意識到它實際上給出了一個錯誤name of window 1
  2. 返回的名稱不包含顏色空間和位數,所以我已經將結果測試更改爲一個空字符串
  3. 通知修改的try塊周圍獲取文件名
  4. 我不認爲有必要或明白了一個道理在這種情況下使用「系統事件」,所以我修改下面的版本沒有它。

腳本示例

 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 
+0

感謝這個幫助;一個noob(當談到Applescript)已經學到了一些東西。這塊代碼解決了這個問題,並且該過程似乎(在沒有那麼多測試之後)正常工作。雖然我們在處理後關閉文檔,但我可能不得不針對已打開的文檔添加一些保護措施。 –

相關問題