It has been a year or two since I have used Applescript so I am a bit rusty. Below are the problems I have been having with the script I currently have and some of the additional items I would like the script to do, but cannot make happen.
Problems:
- Would like to create subfolders within the Data Processing Folder, the new names would be {"Data In", "Data Released"}; This often says that I do not have the variable defined when trying to do this
- I would like for all the files and folders that were inside the dropped folder to move within the AGENCY folder under the Artwork folder; If I try not to do the above #1, I still get an error stating that the operation cannot be completed
Below is the script I have thus far, any and all help would be much appreciated.
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
======UPDATE====== I was able to get the subfolders to create but now I can't get folders to move into the correct subfolder. Can you provide any guidance on this? Please see my latest script below:
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
=======Answer Provided by Vadian prior to being deleted=========
I tried the below on my system which is running macOS Sierra (10.12.2) but it would not run on my system.
*
The major issue the operation cannot be completed occurs because you are going to move all items including the currently new created folders rather than only the existing items before creating the folders. The shell command mkdir can create a folder hierarchy in one line. This is much more efficient than using the Finder. Try this
*
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