【问题标题】:Writing current file path in comment of file in Automator在 Automator 中的文件注释中写入当前文件路径
【发布时间】:2013-12-02 23:15:59
【问题描述】:

我正在尝试在评论文本框中写入当前文件路径;右键单击并获取信息时看到的那个。我已经很接近了,因为我让它为文件夹中的所有文件写入文件路径,但由于某种原因,所有文件路径都是相同的。

例如,当我在运行脚本后右键单击文件并查看注释时,它可能是“'/Users/Admin/Desktop/automator test/folder/spikyBall@2x copy 4.png'”并且它将是所有文件。

我的 Shell Script 变量定义为:

bashFilePath=$(osascript -e 'tell application "Finder" to set filePath to quoted form of posix path of (item 1 of (get selection) as text)');

echo $bashFilePath;

【问题讨论】:

  • 我刚刚发现了一些重要的东西。即使我生成了一个随机数来代替 shell 脚本,所有文件的 cmets 都将是相同的数字。

标签: bash shell path posix automator


【解决方案1】:

如果我正确解释了您的问题,请尝试以下操作:

echo $1

在 shell 脚本中,$1 是第一个参数($2$3 等也可以使用)。所以上面只是呼应了第一个参数......在你的自动化程序中是文件的路径。

【讨论】:

  • 只是回显 $1?这在 cmets 中没有任何内容。
【解决方案2】:

我最终为此使用了纯 Apple 脚本。选择所需的任何文件和文件夹并运行脚本。它也可以在 Automator 中制作成文件或文件夹服务。

tell application "Finder"
    activate
    set fileList to selection

    if (count result) is 0 then
        try
            get (target of front Finder window) as alias
        on error
            choose folder with prompt "Set comments of files in this folder:"
        end try

        try
            set theFolder to result
            set fileList to every file of folder (result) as alias list
        end try
    end if

    display dialog "How would you like to set comments?" buttons {"Overwrite", "Cancel"} default button 2 with title "Set Spotlight Comments current to file path"

    set userInput to the result

    set itemNum to 1



    if (button returned of userInput) is "Overwrite" then
        if (class of first item of fileList) is alias then
            set comment of every file of folder theFolder to POSIX path of (item itemNum of (get selection) as text)
            set itemNum to itemNum + 1
        else
            repeat with thisFile in fileList
                set comment of thisFile to POSIX path of (item itemNum of (get selection) as text)
                set itemNum to itemNum + 1
            end repeat
        end if
    end if

end tell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 2019-08-16
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多