我正在寻找一些帮助来增加更大的苹果脚本,我看到了很多类似的查询,但没有一个完全符合要求,所以如果有人可以帮助或指导我得到答案,那将是一个巨大的帮助,
我想遵循这个一般前提
`“选择名称”默认答案“”将选择名称设置为结果返回的文本
将图像文件夹设置为(选择带有提示“选择图像文件夹:”的文件夹)`
我挣扎的那一点
如果 ImagesFolder 包含名为“Image Set 1”的文件夹,则查看文件夹“Images Set 1”并使用此逻辑重命名内容
如果文件名包含 0001_ 将文件重命名为 ChosenName & “front”
如果文件名包含 0002_ 将文件重命名为 ChosenName & “Back”
如果文件名包含 0003_ 将文件重命名为 ChosenName & “Top”
如果文件名包含 0004_ 将文件重命名为 ChosenNamet & “Bottom”
别的
如果 ImagesFolder 包含名为“Image Set 2”的文件夹,则查看文件夹图像 2 并使用此逻辑重命名内容
如果文件名包含 0001_ 将文件重命名为 ChosenName & “F”
如果文件名包含 0002_ 将文件重命名为 ChosenName & “B”
如果文件名包含 0003_ 将文件重命名为 ChosenName & “T”
如果文件名包含 0004_ 将文件重命名为 ChosenNamet & “B”
(如果有帮助的话,我用来识别这些文件的独特字符总是最后一个字符)
谢谢P
该脚本可以满足您的需求。您需要对其进行扩展以同时管理“Image Set 2”文件夹及其扩展名,但是只需复制 Tell“Finder”块中的内容就很容易了。
因为你有多个文件夹,我使用了一个子程序来处理你的文件夹,每次调用新规则。例如,第一条规则是处理“图像集 1,搜索 0001,0002,0003,0004 并将每个替换为 Front、Back、Top、Bottom。
规则二是处理“Image Set 2,搜索0001,0002,0003,0004,用F、B、T、B替换。
第一部分建立规则。脚本本身被简化为遍历每个规则的循环,调用具有 3 个变量的子例程“Process_SubFolder”:子文件夹名称、当前目标和新名称。
(*
Define record Rule, made of 3 variables :
NFolderNFolder: the name of sub-folder
NSource : the list of part of file names to be processed
NDest : the list of new names. This list MUST count same number of items as NSource
All rules are added into ListRules
*)
global ChosenName, ImagesFolder -- mandatory to use in the sub-routine
set Rule to {NFolder:"Image Set 1", NSource:{"0001", "0002", "0003", "0004"}, NDest:{"Front", "Back", "Top", "Bottom"}}
set ListRules to {Rule}
set Rule to {NFolder:"Image Set 2", NSource:{"0001", "0002", "0003", "0004"}, NDest:{"F", "B", "T", "B"}}
set ListRules to ListRules & {Rule}
set R to display dialog "Enter a name" default answer ""
set ChosenName to text returned of R
if ChosenName is "" then return -- no name selected, end of script
set ImagesFolder to choose folder with prompt "Choose Images Folder:"
repeat with aRule in ListRules
Process_SubFolder(NFolder of aRule, NSource of aRule, NDest of aRule)
end repeat
-- end of main script
on Process_SubFolder(LFolder, LSource, LDest)
tell application "Finder"
set SubFolder to (ImagesFolder as string) & LFolder
if folder SubFolder exists then
set FileList to every file of folder SubFolder -- get all files of Images Set 1
repeat with aFile in FileList -- loop through each file
set FName to name of aFile
set NewName to ""
-- Manage extension of the file
if name extension of aFile is "" then
set NewExt to ""
else
set NewExt to "." & name extension of aFile
end if
repeat with I from 1 to count of LSource --loop trhough each source of the rule
if FName contains (item I of LSource) then set NewName to ChosenName & (item I of LDest) & NewExt
end repeat
if NewName is not "" then set name of aFile to NewName -- only if name must be changed !
end repeat -- loop through files of LFolder
end if -- folder exists
end tell
end Process_SubFolder
使用此结构,您可以添加任意数量的规则!
当然,我假设您永远不会在子文件夹中获得两次相同的名称!在图像集 2 中情况并非如此,您将有 2 个具有新名称 = ChosenNameB 的文件:它会产生错误!!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句