有一种解决方法,但是它不是很漂亮。但是,如果您只想访问一个文件夹(使用您指定的条件)中的自述文件,并且对它们的来源有所了解,它将满足您的目的。
这个想法是使用您的Shell脚本找到正确的文件,然后在一个目录中为每个文件收集别名。然后,我们重命名别名以告诉我们原始文件属于哪个父目录。
下面是执行此操作的Applescript。在这里看起来很丑,但是尝试将其粘贴到脚本编辑器中并进行编译,您应该能够看到逻辑。
--- Set up the name of the folder to contain search results
set myFolder to POSIX file "/Users/me/SmartFolder"
--- Clear the folder of contents. Then we will see only the results of an updated search
tell application "Finder"
display dialog "WARNING. This will delete all files below " & (POSIX path of myFolder) & " . Are you sure you want to continue?"
delete (every item of folder myFolder)
--- alternatively, if you want to keep your script in the same folder, replace the line above with
--- delete ((every item of folder myFolder) whose name does not end with ".scpt")
end tell
--- The shell command that is doing all the searching
set FileList to do shell script "find /Users/me/Documents -type f -name README.md -not -path '*/node_modules/*'"
--- The rest of the script takes each file and makes an alias in our folder containing search results. The aliases are renamed according to "ParentDirectory_filename"
set FileList to paragraphs of FileList
repeat with CurrentFile in FileList
set ASCurrentFile to POSIX file CurrentFile
set PathList to words of (ASCurrentFile as string)
--- Make the new name include the Parent Directory and file name
set NewName to (item -2 of PathList) & "_" & (item -1 of PathList)
tell application "Finder"
make new alias file at myFolder to ASCurrentFile
--- We need to save the name/location of the new alias file before we can try to rename it
set NewAlias to result
set i to 1
repeat
try
--- Try to rename the alias. Won't work if there's already an alias with the new name
set name of NewAlias to NewName
exit repeat
on error
--- Append a number to the alias. Increase the number for more duplicates
if i is not equal to 1 then
set NewName to text 1 thru -3 of NewName
end if
set NewName to NewName & " " & i
set i to (i + 1)
end try
end repeat
end tell
end repeat