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

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

如何添加将使用单个选定文件的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的新手,无法弄清楚如何使其正常工作。任何帮助表示赞赏。

macos shell applescript automator finder
1个回答
1
投票

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
© www.soinside.com 2019 - 2024. All rights reserved.