(这是我上一个问题的新编辑,获得了-3票。希望这个新的有更好的资格)
我需要创建一个Automator 服务来将大量文件组织到文件夹中。我与illustrator合作,从每个.ai文件中我创建了另外3 种格式:[ name.pdf ]、[ name BAJA.jpg ] 和 [ name.jpg ] ,总共 4 个文件
我的问题是,在一周内,我对 90 多个不同的 .ai 文件重复此过程。所以 90 个文件 * 4 是360 个独立的文件都到某个项目文件夹中。
我想将所有 4 个相关文件抓取到一个文件夹中,并将文件夹名称设置为与 .ai 文件相同。
由于所有文件名都是相同的(除了一个),我想告诉 finder 抓取所有同名的文件,复制名称,创建一个文件夹并将这些文件放入其中,但我有一个文件名变体 [name LOW.jpg] 也许我可以告诉脚本将其作为例外剥离。
这样我会将所有 4 个文件统一到一个文件夹中。先感谢您
更新:这个问题最初是在 2013 年发布的,现在我有一个解决方案。人们帮我组装了这个脚本以满足我的需要。
我将此添加为一项服务,并在 MacO 上分配了一个键盘快捷键。这是代码:
on run {input, parameters} -- create folders from file names and move
set output to {} -- this will be a list of the moved files
repeat with anItem in the input -- step through each item in the input
set {theContainer, theName, theExtension} to (getTheNames from anItem)
try
# check for a suffix and strip it off for the folder name
if theName ends with " BAJA" then
set destination to (makeNewFolder for (text 1 thru -6 of theName) at theContainer)
else
set destination to (makeNewFolder for theName at theContainer)
end if
tell application "Finder"
move anItem to destination
set the end of the output to the result as alias -- success
end tell
on error errorMessage -- duplicate name, permissions, etc
log errorMessage
# handle errors if desired - just skip for now
end try
end repeat
return the output -- pass on the results to following actions
end run
to getTheNames from someItem -- get a container, name, and extension from a file item
tell application "System Events" to tell disk item (someItem as text)
set theContainer to the path of the container
set {theName, theExtension} to {name, name extension}
end tell
if theExtension is not "" then
set theName to text 1 thru -((count theExtension) + 2) of theName -- just the name part
set theExtension to "." & theExtension
end if
return {theContainer, theName, theExtension}
end getTheNames
to makeNewFolder for theChild at theParent -- make a new child folder at the parent location if it doesn't already exist
set theParent to theParent as text
if theParent begins with "/" then set theParent to theParent as POSIX file as text
try
return (theParent & theChild) as alias
on error errorMessage -- no folder
log errorMessage
tell application "Finder" to make new folder at theParent with properties {name:theChild}
return the result as alias
end try
end makeNewFolder
希望这可以帮助。