我已经搜索了数周,但未能在我的 Mac 上运行 Ventura 找到一种方法来帮助解决这个问题。
我有很多文件具有相同的文件名,并以不同的扩展名保存,并且都存在于同一个文件夹中。我正在寻找一个脚本来用作将执行以下操作的文件夹操作。
例子;
观看的文件夹位置在我名为“工作”的主文件夹中。
Example Print.ai
Example Print.mkv
Example Print.jpg
Example Print.txt
Weird Logo 3454.psd
Weird Logo 3454.ai
Weird Logo 3454.png
Weird Logo 3454.gif
Green Bird.png
Green Bird.jpg
Lizard Jumping.mkv
理想情况下,如果在所有这些项目所在的文件夹“工作”上作为文件夹操作运行,它将返回以下结果;
/users/blaine/work/Example Print/
Example Print.ai
Example Print.mkv
Example Print.jpg
Example Print.txt
/users/blaine/work/Weird Logo 3454/
Weird Logo 3454.psd
Weird Logo 3454.ai
Weird Logo 3454.png
Weird Logo 3454.gif
/users/blaine/work/Green Bird/
Green Bird.png
Green Bird.jpg
/users/blaine/work/Lizard Jumping.mkv
打开文件夹“工作”时应该看起来像这样。
/users/blaine/work/Example Print/
/users/blaine/work/Weird Logo 3454/
/users/blaine/work/Green Bird/
/users/blaine/work/Lizard Jumping.mkv
有什么想法吗?我设法创建了一个快捷方式,允许我运行“快速操作”,我可以在排序时手动突出显示文件并从选择中创建新文件夹并自动将新文件夹命名为与不带扩展名的文件名相同的名称,但是有成千上万,这让我相信一定有更好的方法。任何帮助表示赞赏。
这些是我能找到的关于这个主题的最接近的线索,但它们有点不同,我无法剖析和创作。
试试这个。添加到热(监视)文件夹的文件将被移动到热文件夹的相应子文件夹中。
on adding folder items to thisFolder after receiving these_items
set thisFolderHFSPath to thisFolder as text -- this watch folder's HFS path
repeat with anItem in these_items
set baseName to my getBaseName(POSIX path of anItem) -- baseName of file
tell application "Finder"
try -- will determine file's appropriate subfolder
set subFolder to folder (thisFolderHFSPath & baseName)
on error -- if no appropriate subfolder, then create it
set subFolder to make new folder at thisFolder with properties {name:baseName}
end try
try -- required try block here
move file (anItem as text) to subFolder
end try
end tell
end repeat
end adding folder items to
on getBaseName(posixPath)
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
if (posixPath ends with "/") then
set baseName to text item -2 of posixPath
else
set baseName to text item -1 of posixPath
end if
if (baseName contains ".") then
set AppleScript's text item delimiters to "."
set baseName to text 1 thru text item -2 of baseName
end if
set AppleScript's text item delimiters to ATID
return baseName
end getBaseName