2014-10-03 61 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