【发布时间】:2017-03-24 13:53:12
【问题描述】:
我使用 Applescript 已经一两年了,所以我有点生疏了。以下是我目前使用的脚本遇到的问题,以及我希望脚本执行但无法实现的一些附加项目。
问题:
- 想要在数据处理文件夹中创建子文件夹,新名称将是 {"Data In", "Data Released"};这通常表示我在尝试执行此操作时没有定义变量
- 我希望将放置文件夹中的所有文件和文件夹移动到 Artwork 文件夹下的 AGENCY 文件夹中;如果我尝试不执行上述 #1,我仍然会收到一条错误消息,指出操作无法完成
以下是我到目前为止的脚本,非常感谢任何和所有帮助。
on adding folder items to this_folder after receiving added_items
-- added_items is a _list_ of the items just added, even when there's only one. Deal with each item in turn.
repeat with this_item in added_items
tell application "Finder"
-- 'item this_item' gets a Finder reference to the item so that its class can be determined.
if (class of item this_item is folder) then
try
-- Make new folders in this dropped folder.
set client_files_folder to (make new folder in this_item with properties {name:"Artwork"})
make new folder in client_files_folder with properties {name:"AGENCY"}
make new folder in client_files_folder with properties {name:"EXPORT_TO_XMPIE"}
make new folder in client_files_folder with properties {name:"XMPIE"}
make new folder in this_item with properties {name:"Data Processing"}
make new folder in this_item with properties {name:"Imaging_Laser"}
make new folder in this_item with properties {name:"Production Report"}
make new folder in this_item with properties {name:"Program Plan"}
-- Move the following items from the dropped folder to the just-created "AGECNY" folder.
move {every folder of this_item} to client_files_folder
on error errMsg
display dialog errMsg
end try
end if
end tell
end repeat
end adding folder items to
======更新====== 我能够创建子文件夹,但现在我无法让文件夹移动到正确的子文件夹中。您能对此提供任何指导吗?请在下面查看我的最新脚本:
on adding folder items to this_folder after receiving added_items
-- added_items is a _list_ of the items just added, even when there's only one. Deal with each item in turn.
repeat with this_item in added_items
tell application "Finder"
-- 'item this_item' gets a Finder reference to the item so that its class can be determined.
if (class of item this_item is folder) then
try
-- Make new folders in this dropped folder.
set ART_Folder to (make new folder in this_item with properties {name:"Artwork"})
set Data_Folder to (make new folder in this_item with properties {name:"Data Processing"})
set Agency_Folder to (make new folder in ART_Folder with properties {name:"AGENCY"})
make new folder in ART_Folder with properties {name:"EXPORT_TO_XMPIE"}
make new folder in ART_Folder with properties {name:"XMPIE"}
make new folder in Data_Folder with properties {name:"Data In"}
make new folder in Data_Folder with properties {name:"Data Released"}
make new folder in this_item with properties {name:"Imaging_Laser"}
make new folder in this_item with properties {name:"Production Report"}
make new folder in this_item with properties {name:"Program Plan"}
-- Move the items from the dropped folder to the just-created "AGECNY" folder.
move folders in this_item to Agency_Folder
on error errMsg
display dialog errMsg
end try
end if
end tell
end repeat
end adding folder items to
=======Vadian 在被删除之前提供的答案=========
我在运行 macOS Sierra (10.12.2) 的系统上尝试了以下操作,但它无法在我的系统上运行。
*
无法完成操作的主要问题是因为您 将移动所有项目,包括当前新创建的 文件夹,而不仅仅是创建之前的现有项目 文件夹。 shell 命令 mkdir 可以在一个文件夹中创建文件夹层次结构 线。这比使用 Finder 更有效。试试这个
*
on adding folder items to this_folder after receiving added_items
repeat with this_item in added_items
tell application "Finder"
if (class of this_item is folder) then
set allItems to every item of this_item
do shell script "mkdir -p " & quoted form of POSIX path of this_item & "{Artwork/{AGENCY,EXPORT_TO_XMPIE,XMPIE},'Data Processing'/{'Data In','Data Released'},Imaging_Laser,'Production Report','Program Plan'}"
-- Move the following items from the dropped folder to the just-created "AGECNY" folder.
move allItems to folder "Artwork:AGENCY:" of this_item
end if
end tell
end repeat
end adding folder items to
【问题讨论】:
-
我在回答中解释了为什么您的脚本无法运行。我删除了答案,因为您完全忽略了我的建议。
-
Vadian - 我实际上尝试了您的脚本,但它对我不起作用。我照原样复制并粘贴它,根本没有处理文件。这根本不是你。我感谢任何人和每个人的时间。我正在使用 OS Sierra,我相信在 Applescript 方面该操作系统存在一些错误
标签: applescript