【问题标题】:AppleScript with multiple finder inputs具有多个查找器输入的 AppleScript
【发布时间】:2016-04-05 20:46:00
【问题描述】:

是什么以及为什么 在 Finder 中,我希望能够通过简单的右键单击来隐藏任何文件/文件夹,无论是否需要 sudo。

已经采取的步骤: 经过一堆试验后,我选择了一个运行 AppleScript 的 Automator 服务

on run {input, parameters}
  set filehide1 to {}
  repeat with filehide2 in input
  set end of filehide1 to POSIX path of filehide2
  end repeat
  do shell script "chflags hidden " & quote & filehide1 & quote with administrator privileges
end run

问题: 因此,仅当一次选择一个项目时,该脚本才能以目前的形式工作。无论是 1 个文件还是 500 个文件,我如何调整 Automator / AppleScript 以使其正常工作?

【问题讨论】:

    标签: macos shell applescript osx-yosemite automator


    【解决方案1】:

    您不能将 AppleScript 列表传递给 shell。您必须展平列表并用空格字符分隔文件路径。这可以通过text item delimiters 完成。

    脚本在重复循环中对每个文件路径进行转义,因此do shell script 行中不需要引号。

    on run {input, parameters}
        set filehide1 to {}
        repeat with filehide2 in input
            set end of filehide1 to quoted form of POSIX path of filehide2
        end repeat
        set {TID, text item delimiters} to {text item delimiters, space}
        set fileList to filehide1 as text
        set text item delimiters to TID
        do shell script "chflags hidden " & fileList with administrator privileges
    end run
    

    【讨论】:

    • 非常感谢!我应该早点寻求帮助,而不是因为谷歌让我失望而大喊大叫。干杯,新年快乐!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    相关资源
    最近更新 更多