如何使用AppleScript从批量图像中删除alpha

问题描述 投票:1回答:1

我有大量的图像,我需要从每个图像中删除alpha。这在预览应用程序中是可行的,但是我需要重复这一次的过多时间太费时间了。

我听说过AppleScript并在自动化过程中做了一些微弱的尝试,目前无济于事。

我正在使用这样的东西,然后开始重复,但它只允许我循环一个直接文件夹(我也遇到菜单栏项目的麻烦)

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

但我在文件夹中有多个文件夹,我希望更改一定数量的图像。文件夹结构是这样的:

用户/用户/文件夹/ ImagesRoot /

在ImagesRoot里面是3个文件夹和一个txt文件。我想专门选择2个名为“Icons”和“Screenshots”的文件夹。在“图标”中有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是一个很好的方法,但也有可能吗?但是,我有2%的使用AppleScript的经验,可能有4%的bash,并且不知道如何处理它。

任何建议或帮助将不胜感激。

谢谢

bash applescript
1个回答
0
投票

据我所知,即使您使用enable AppleScripting,预览也无法更改文档的alpha。在支持它的应用程序中,例如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通道”设置为“删除”的“获取文件夹内容”和“重复”的组合可能就是您所需要的。如果您需要排除某些文件,Filter Finder Items会执行此操作。

但是,如果要使用“预览”,则可以使用“系统事件”。就像是:

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

如果您选择辅助访问路线,您可能会发现Apple帮助签署有用的应用程序:http://support.apple.com/kb/HT5914

© www.soinside.com 2019 - 2024. All rights reserved.