如何添加将使用单个选定文件的Finder服务,在该文件上执行Shell脚本,然后将其显示为对话框窗口?

时间:2019-11-19 17:40:01

标签: macos shell applescript automator finder

如何添加将使用单个选定文件的Finder服务,在该文件上执行Shell脚本,然后将其显示为对话框窗口?

我目前有Automator在Finder中接收文件和文件夹,然后使用以下命令运行Applescript:

on run {input, parameters}
    tell application "Finder"

        set filename to selection
        set filename to quoted form of POSIX file filename
        set theCMD to "/usr/local/bin/exiftool "
        set theScript to theCMD & filename
        set theResult to do shell script theScript
        display dialog theResult
    end tell
end run

我不断收到错误。目的是在Finder窗口中显示一个对话框窗口,其中包含有关单个选定文件的Exif元数据信息。我用brew安装exiftool来检索数据。

我是applescript的新手,不知道如何使它工作。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

Automator服务将输入项传递到工作流,因此您无需执行任何其他操作即可获得选择。在运行AppleScript 操作中,input参数是一个列表,因此您应该选择一个特定的项目,或者只是循环浏览所有项目:

on run {input, parameters}
    repeat with anItem in the input
        set anItem to quoted form of POSIX path of anItem
        set theResult to (do shell script "/usr/local/bin/exiftool " & anItem)
        display dialog theResult
    end repeat
    # return input
end run