我正在尝试在评论文本框中写入当前文件路径;右键单击并获取信息时看到的那个。我非常接近,因为我让它为文件夹中的所有文件写了一个文件路径,但由于某种原因,所有文件路径都是相同的。
例如,当我在运行脚本并查看注释后右键单击文件时,它可能是“'/ Users / Admin / Desktop / automator test / folder / spikyBall @ 2x copy 4.png'”并且它将是所有文件的。
My 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;
答案 0 :(得分:0)
如果我正确解释您的问题,请尝试以下方法:
echo $1
在shell脚本中,$1
是第一个参数($2
,$3
等也可以工作)。所以上面只是回应了第一个参数......你的automator程序就是文件的路径。
答案 1 :(得分:0)
我最终使用了纯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