If I think that the task is more than a simple help one, I stop helping.
As I’m retired I refuse to work for money. I know that developers must earn their lives and wish that the problem is transferrer to such being.
Some years ago I accepted to help someone but, as the exchange became long I decided to continue offlist.
What an error ! During three months everyday a new question was added when the one asked on eve was solved.
As I learnt interesting things in the process I tried to be patient but at last it was really too much and I closed the exchanges.
Now I accept no exception.
Oops, I just saw that I missed the request for a text file named “workspace.mel” in the subfolder 3D.
I edited the script and pasted it in message #4
I’m not sure of what you ment with :
Must I understand that the quicktime file must not be moved at the root of its folder but in the subfolder plates ?
If it’s that, what to do when the file is a picture one ?
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) vendredi 28 juillet 2017 19:45:40
Editing the script so that the original file is moved into HTG101_100_001/plates/plate.
What is problematic is the treatment of the folder HTG100_101_001_bg_plt_v001 because, as I’m not a sooth sayer, I am unable to guess where it is stored when we call the script.
Remember, the script is aware of the location of the movie because it’s selected.
Must I understand that the selection contain the movie file AND the folder which appear now like a Jack in a Box.
QUESTION: You wrote :
HTG101_100_001.mov should end up in
…I would have a folder called HTG100_101_001_bg_plt_v001
If I read well, 101_100 in the filename became 100_101 in the folder name.
Is it the truth or is it a typo ?
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) vendredi 28 juillet 2017 20:52:17
HTG001_002_bg_plt_v001 – a folder
HTG001.mov – a movie
HTG105_001_bg_plt_v001 – a folder
HTG105.mov – a movie
HTGflyer_bg_plt_v001 – a folder
HTGflyer.dpx – a picture
HTGNick Brignola_bg_plt_v001 – a folder
HTGNick Brignola.mp4 – a movie
Here, the code is ready to treat this kind of data.
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) vendredi 28 juillet 2017 21:19:37
Selected folder would contain; ANY/EITHER of the following
selectedFolder
HTG100_101_001_bg_plt_v001 (a folder)
HTG100_101_001.mov (a movie)
SDL100_101_001_bg_plt_v001 (a folder)
SDL100_101_001.mov (a movie)
So any folder selected with either folders or movies or even a combination of the two, could sort them into the folder structure. With all variations ending up in the plate directory.
Does that help?
Also, I’m in California, so I know you’re 9 hours ahead of me. I appreciate you staying up as late as you have!!
FYI my family and I were just in London/Paris last month, it’s a beautiful country. We only got to spend about 8 hours in Paris after taking the Eurostar out for the day. My wife already wants to go back!
I replaced the script by a new version.
I’m not sure that it fully match your needs.
It assume that every folder available is accompanied by at least one file.
On entry it builds a list of files available and a list of folders available.
In a loop, it creates the hierarchy of subfolders required by one file
then it search for a folder whose name match the given rules.
If it find one, it move it as required
at last it moves the file itself.
So, if a folder exists but no “associated” file is available, the folder is not treated.
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) samedi 29 juillet 2017 11:36:59
Here, based on my understanding of the discussion above, is a version which creates all the folder hierarchies with a single shell script and then creates the text files and moves the original files. I’m not clear what extension’s meant in “blank text document labeled the name of the quicktime, with a _v001 before the extension.” I’ve assumed “.txt”, which is what I’d expect with a text file.
tell application "Finder"
set selected to selection
-- Selection assumed here to consist of just 1 folder containing movie files or folders or both, all to be treated in the same way.
set selected_folder to item 1 of selected as alias
-- Get the folder's items and, separately, their names.
set original_items to every item of selected_folder
set item_names to name of every item of selected_folder
end tell
-- Derive quoted and unquoted forms of the names, without extensions, to use for the folders.
set shot_folder_names to {}
set quoted_shot_folder_names to {}
set astid to AppleScript's text item delimiters
repeat with this_name in item_names
-- If a name has an extension, lose the extension. Otherwise assume it's a folder name containing "_bg_plt_v" and lose everything from that point.
if (this_name contains ".") then
set AppleScript's text item delimiters to "."
else
set AppleScript's text item delimiters to "_bg_plt_v"
end if
set end of shot_folder_names to text 1 thru text item -2 of this_name
set end of quoted_shot_folder_names to quoted form of result
end repeat
--- Put together a path formula representing all the required "shot folder" hierarchies.
set item_count to (count quoted_shot_folder_names)
if (item_count > 1) then
-- More than one shot folder name. Get a text containing them all, comma-delimited and in braces.
set AppleScript's text item delimiters to ","
set shot_folder_name_group to "{" & quoted_shot_folder_names & "}"
else if (item_count is 1) then
-- Only one shot folder name.
set shot_folder_name_group to item 1 of quoted_shot_folder_names
else
set AppleScript's text item delimiters to astid
error "The selected folder is either empty or not a folder!"
end if
set AppleScript's text item delimiters to astid
set hierarchy_formula to quoted form of POSIX path of selected_folder & shot_folder_name_group & "/{2D/{ae,mocha,nuke,ps},3D/{cache,data,scenes,textures},plates/{etc,plate,proxy},renders/{comp,graphics,ibtw,lightning,mattes,playblasts,precomp,quicktimes,temp}}"
-- Use it to create the shot folder hierarchies.
do shell script "mkdir -p " & hierarchy_formula
-- Move stuff into each shot folder hierarchy in turn.
set selected_folder_path to selected_folder as text
repeat with i from 1 to (count shot_folder_names)
set this_shot_folder_name to item i of shot_folder_names
set shot_folder_path to selected_folder_path & this_shot_folder_name
-- Create a text file in the "3D" folder.
close access (open for access file (shot_folder_path & ":3D:workspace.mel"))
-- And one each in the "2D:ae" and "2D:ps" folders.
set text_file_name to this_shot_folder_name & "_v001.txt"
close access (open for access file (shot_folder_path & ":2D:ae:" & text_file_name))
close access (open for access file (shot_folder_path & ":2D:ps:" & text_file_name))
-- Move the original item into the "plates:plate" folder.
tell application "Finder" to move (item i of original_items) to folder (shot_folder_path & ":plates:plate") -- replacing yes
end repeat
PS. The hierarchy_formula string shown above stops at the right margin in my browser, but it’s complete in the “Open in this Scriplet” link.
Edit: Destination folder for original item(s) corrected in the light of Yvan’s comment below. Folders in the selected folder now handled too and in the same way as files. Single-item formula bug fixed.
You missed a part of the task which, as it’s alas often the case, was not described at first.
Here it was introduced in message #7 and is about folders which must be moved into the newly created folders.
Beyond that, your script move the original files in a wrong location.
It moves them in this kind of location :
“SSD 500:Users:???mov copie:HTG001_002:plates:HTG001_002.mov”
when it’s supposed to be :
“SSD 500:Users:???mov copie:HTG001_002:plates:plate:HTG001_002.mov”
Have fun with that.
To correct that I made some changes:
# Instruction added at the very beginning
set theFolders to name of every folder of current_folder # ADDED
# Instruction edited to move in the correct location
tell application "Finder" to move (item i of mlist) to folder (path_to_hierarchy & ":plates:plate") -- replacing yes # EDITED
# some instructions moving the additional folders
tell application "Finder"
set pass to 0
repeat with fName in theFolders
set fName to fName as text
if fName = this_folder_name & "_bg_plt_v001" then
move folder (current_folder_path & fName) to folder path_to_hierarchy
exit repeat
end if
end repeat
end tell
Other feature : In my tests, if there is a single file in the selected folder, the script fails after creating a folder whose name is enclosed between parenthesis.
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) samedi 29 juillet 2017 13:46:39
Oops. Thanks, Yvan. Now corrected. I’ll have a look at the folder business this afternoon.
Edit: Folder business now fixed too — if I’ve correctly understood that any folders in the selected folder are to be treated in the same way as files apart from the derivation of the “shot folder” names. I’ve also fixed the bug Yvan discovered which occurs when there’s only one item in the selected folder.
Thanks for the feedback.
May you tell which location is the correct one for the folder.
I put it at the root of the file dedicated folder while Nigel puts it in the plate subfolder.
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) dimanche 30 juillet 2017 11:32:49
on open dropped_items
-- Examine each of the one or more dropped items in turn.
repeat with dropped_folder in dropped_items
-- Is this dropped item actually a folder?
tell application "Finder" to set is_Folder to (class of item (dropped_folder as text) is folder)
-- Act only if it is.
if (is_Folder) then
tell application "Finder"
-- Get the folder's items and, separately, their names.
set original_items to every item of dropped_folder
set item_names to name of every item of dropped_folder
end tell
-- Derive quoted and unquoted forms of the names, without extensions, to use for the folders.
set shot_folder_names to {}
set quoted_shot_folder_names to {}
set astid to AppleScript's text item delimiters
repeat with this_name in item_names
-- If a name has an extension, lose the extension. Otherwise assume it's a folder name containing "_bg_plt_v" and lose everything from that point.
if (this_name contains ".") then
set AppleScript's text item delimiters to "."
else
set AppleScript's text item delimiters to "_bg_plt_v"
end if
set end of shot_folder_names to text 1 thru text item -2 of this_name
set end of quoted_shot_folder_names to quoted form of result
end repeat
--- Put together a path formula representing all the required "shot folder" hierarchies.
set item_count to (count quoted_shot_folder_names)
if (item_count > 1) then
-- More than one shot folder name. Get a text containing them all, comma-delimited and in braces.
set AppleScript's text item delimiters to ","
set shot_folder_name_group to "{" & quoted_shot_folder_names & "}"
else if (item_count is 1) then
-- Only one shot folder name.
set shot_folder_name_group to item 1 of quoted_shot_folder_names
else
set AppleScript's text item delimiters to astid
error "The selected folder is either empty or not a folder!"
end if
set AppleScript's text item delimiters to astid
set hierarchy_formula to quoted form of POSIX path of dropped_folder & shot_folder_name_group & "/{2D/{ae,mocha,nuke,ps},3D/{cache,data,scenes,textures},plates/{etc,plate,proxy},renders/{comp,graphics,ibtw,lightning,mattes,playblasts,precomp,quicktimes,temp}}"
-- Use it to create the shot folder hierarchies.
do shell script "mkdir -p " & hierarchy_formula
-- Move stuff into each shot folder hierarchy in turn.
set dropped_folder_path to dropped_folder as text
repeat with i from 1 to (count shot_folder_names)
set this_shot_folder_name to item i of shot_folder_names
set shot_folder_path to dropped_folder_path & this_shot_folder_name
-- Create a text file in the "3D" folder.
close access (open for access file (shot_folder_path & ":3D:workspace.mel"))
-- And one each in the "2D:ae" and "2D:ps" folders.
set text_file_name to this_shot_folder_name & "_v001.txt"
close access (open for access file (shot_folder_path & ":2D:ae:" & text_file_name))
close access (open for access file (shot_folder_path & ":2D:ps:" & text_file_name))
-- Move the original item into the "plates:plate" folder.
tell application "Finder" to move (item i of original_items) to folder (shot_folder_path & ":plates:plate") -- replacing yes
end repeat
end if
end repeat
end open
I’ve been using the script successfully for a little while now with no complaints.
I did find one operational thing that I didn’t consider, and wondered if there’s an easy way to change one small thing.
I’m using another script inside AE that references the specific folder structure that you’ve built for me. But I made an error when I asked for the name of the text file inside the 2d/ps folder and 2d/ae folder. In other words, your work is perfect… I’m the idiot that didn’t ask for the right thing!!
The text file needs to be named with “_main_comp” in it’s title.
So current results create the following: gon102_006_005_v001.txt
but it needs to add “_main_comp” so it should read gon102_006_005_main_cmp_v001.txt
Would it be possible to alter the existing script to include this?
I tried figuring out how to alter it in the existing script, but that part’s not in plain english… and is sadly way outside my level of comprehension.