从finder选择中获取POSIX PATH

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

我想用automator和applescript来建立一个能够在finder中ls所选文件夹的快速动作。我不能让它工作。它总是回到错误 "Can't get the POSIX Path"。这是我目前的代码。

on run {input, parameters}
            tell application "Finder" to set theFiles to POSIX path of input
            tell application "Terminal"
                do shell script "ls " & theFiles
                activate
            end tell
            return theFiles
        end run

谢谢。

shell terminal applescript automator
1个回答
1
投票

这里是一个 自动机 服务项目 我使用的,你可以根据自己的喜好进行调整。

on run {input, parameters}
    set theseFinderItems to {}
    repeat with aItem in input
        copy quoted form of POSIX path of aItem to end of theseFinderItems
        copy space to end of theseFinderItems
    end repeat
    tell application "Terminal"
        do script "ls -aleO@ " & theseFinderItems
    end tell
end run

enter image description here

下面是一个示例输出 终端 当选择 查找器 而后 ls -aleO@ Finder Items 服务项目,其中 macOS莫哈韦 而后被称为 快速行动.

$ ls -aleO@ '/Volumes/RAMDisk/CAT RP6500/Service Manual - CM20160617-56278-18523.pdf' 
-rw-r--r--@ 1 me  staff  - 7061976 Jun  1 21:08 /Volumes/RAMDisk/CAT RP6500/Service Manual - CM20160617-56278-18523.pdf
    com.apple.lastuseddate#PS        16 
    com.apple.metadata:kMDItemDownloadedDate         53 
    com.apple.metadata:kMDItemWhereFroms        116 
    com.apple.quarantine         57 
$

注: 例子 AppleScript 编码 就是这样,不包含任何 错误处理 视情况而定。用户有责任添加任何。错误处理 可能是适当的、需要的或想要的。请看一下 尝试 声明错误 声明AppleScript语言指南. 另见: 处理错误. 此外,还使用了 拖延 指挥 适当情况下,可能需要在两次活动之间进行,如 delay 0.5例如,随着 价值拖延 适当地设置。

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