首页 > 解决方案 > 如何添加将使用单个选定文件的 Finder 服务,在其上执行 shell 脚本,然后将其显示为对话框窗口?

问题描述

如何添加将使用单个选定文件的 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的新手,不知道如何让它工作。任何帮助表示赞赏。

标签: macosshellapplescriptautomatorfinder

解决方案


Automator 服务将输入项传递给工作流,因此您无需执行任何其他操作即可获得选择。在Run 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

推荐阅读