2014-10-03 59 views
1

我有大量的圖像,其中我需要從每個圖像中刪除alpha。這可以從預覽應用程序中實現,但我需要重複的絕對時間太耗時。如何使用AppleScript從批量圖像中刪除Alpha

我聽說過AppleScript,並在自動化過程中做出了一些微弱的嘗試,目前無濟於事。

我使用這樣的事情,然後開始重複,但只允許我遍歷一個直接的文件夾(也我在與菜單欄項的麻煩)

set fl to files of folder POSIX file "/Users/user/Documents/" as alias list 

但我有多重我想更改大量圖像的文件夾內的文件夾。文件夾結構是這樣的:

用戶/用戶/文件夾/ ImagesRoot/

在內部ImagesRoot是3個文件夾和一個txt文件。我想專門選擇2個名爲「圖標」和「屏幕截圖」的文件夾。在「圖標」中是5張圖片。然而,「屏幕截圖」包含3個子文件夾,每個子文件夾都有自己的5個圖像。 (可簡稱爲「Screensub 1,2,3」)

一旦收到這樣的文件夾內的圖像列表,過程會像

tell application "Preview" 
    open the image file 
    open the file menu 
    open export... 
    untick alpha 
    press save 
    press replace 
    close window 
end tell 
Loop to next one 
when looped through all in Icons folder, do all 5 images of each subfolder of screenshot folder 

據我所知,AppleScript的是一個很好的這樣做的方式,但也是一個可能性bash? 但是,我有2%的經驗與applescript和可能4%的bash,並不知道如何處理它。

任何意見或幫助將不勝感激。

感謝

回答

0

據我所知,預覽不必更改文檔的α的能力,即使你enable AppleScripting。在不支持它,如GraphicConverter的應用程序,這是一個相當簡單的任務:

on open imageFile 
    tell application "GraphicConverter 9" 
     open imageFile 
     tell window 1 
      set alpha to false 
     end tell 
     --save image as needed 
    end tell 
end open 

您可能會發現它更容易使用的Automator。的組合獲取文件夾內容重複每個子文件夾中Alpha通道設置爲刪除可能是你所需要的。如果你需要排除一些文件,篩選器查找項目會做到這一點。

但是,如果您想使用預覽功能,則可以使用系統事件。喜歡的東西:

on open imageFile 
    tell application "Preview" 
     open imageFile 
     activate 
     set filename to name of window 1 
     tell application "System Events" 
      tell process "Preview" 
       click menu item "Export…" of menu "File" of menu bar 1 
       tell sheet 1 of window 1 
        --rename file 
        set value of text field 1 to filename & " Alpha Removed" 

        --uncheck alpha channel 
        tell checkbox 1 of group 1 
         click 
        end tell 

        --save 
        click button "Save" 
       end tell 
      end tell 
     end tell 
    end tell 
end open 

如果你選擇的輔助訪問路線,你會發現蘋果的有用簽署應用程序的幫助:http://support.apple.com/kb/HT5914

+0

導出時,預覽將有tickbox你是否希望阿爾法(只有當它檢測它) – invisibloom 2014-10-03 18:30:37

+0

感謝您的建議,我正在尋找圖形轉換器,它似乎promisinh – invisibloom 2014-10-03 18:31:20

+0

是的,我假設你想要刪除alpha通道的所有文件都有一個alpha通道。如果不是這樣,你可能需要修改一些腳本。此外,對於使用其自己的內置批處理系統或使用AppleScript的批處理,GraphicConverter非常有用。 – 2014-10-03 18:32:09