[英]Applescript to Create Watch Folder and move files within dropped files and created folders
自從我使用Applescript已經一兩年了,所以我有點生銹。 以下是我目前使用的腳本遇到的問題以及我希望腳本執行但無法實現的一些其他事項。
問題:
以下是我到目前為止擁有的腳本,我們將不勝感激。
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
經過大量測試和檢查Stack Exchange及其各種貢獻者之后,我能夠將以下代碼組合在一起以滿足我在帖子中概述的目標
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. If you want to be able to have subfolders created for any of your structure you would have to list as shown below
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"})
-- The below shows subfolders and how to input if you want additional folders inside of folders
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 (every file of this_item) to Agency_Folder
move (every folder of this_item whose name is in {"Links", "Lowres PDFs"}) to Agency_Folder
move (every folder of this_item) to Agency_Folder
on error errMsg
display dialog errMsg and (say "error")
end try
end if
end tell
end repeat
end adding folder items to
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.