Clean-up Folder Script

Thanks, James. I’ll give it a try and report back. But you are right, getting a list together and having the artists do some manual file clean-up is what they’ll need to do. I can’t imagine writing a new script for everyone’s different workflow or file structure. Besides, that’s what they get for not following the initial script.

Thanks again, James. I’ll follow up with any results.

Alex:lol:

Dear James:
I got to the bottom of why the creatives were not using the “New Project” script correctly. It appears that they didn’t like that the Project Number was being placed as a “prefix” to the Project Name. So they either deleted the number after the script generated the project folders or would not use the script at all. So in an effort to move forward, I’m needing to revamp the “New Project” script to place the Project Number as a “suffix”. I had someone help me put together the New Project script and I can’t remember nor can I decipher some of the subroutines within the script.

Can you help me understand how the “prefix” subroutine works and is it possible to change it to a “suffix” instead?

Here are the steps I need it to run through:

  1. Enter Project Name and choose a destination.
  2. Enter Project Number as part of the Parent Folder name but as a suffix still separated by a “-”. (no need for the Project Name to show up as part of the Default Name. Just a dialog to add the number)
  3. The script would generate the Sub-folders as before but again, adding the project number as a suffix instead.

Any insights would be greatly appreciated. I’ve been working the last couple of days to fix this but it just keeps erroring out. Also, would this change affect the Clean-up script you helped me with?

Here’s the entire New Project script

Hi Alex, here is an updated script to make your folders

--Make a choice for server folder type--
display dialog ¬
	"Select New Project to Start or Cancel Process" buttons {"New Project", "Cancel"}
set the button_pressed to the button returned of the result

--To make  New Project server--
if the button_pressed is "New Project" then
	
	-- Prompt for a prefix.
	set suffix to text returned of (display dialog "Please enter a job number for the project folder names." default answer "-Project Number" with icon note)
	if suffix does not start with "-" then set suffix to "-" & suffix
	
	-- Use a "Save as." dialog to set the name and location for this project folder.
	set parentFolder to (choose file name with prompt "Enter a Project Name & Pick a Destination" default name (suffix))
	set parentPosix to quoted form of POSIX path of parentFolder
	
	-- Assemble the mkdir command.
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ""
	set mkdirStr to {"mkdir -p ", parentPosix, "/", "{Comps,Copy,Images,Collected,Reference,PDF}", suffix} as Unicode text
	set AppleScript's text item delimiters to astid
	
	-- Create the folders.
	do shell script mkdirStr
end if

And expect an updated clean up script later this evening =)

And here is the clean-up script for having a job number at the end of the Project Name

-- Choose the parent folder
set parentFolder to (choose folder) as string


-- Set up our base variables
tell application "Finder" to set parentFolderName to name of alias parentFolder
set jobNumber to text ((offset of "-" in parentFolderName) + 1) thru -1 of parentFolderName
set posixPath to POSIX path of parentFolder


-- Remove all zip archives from Parent Folder:Collected
set posixCollected to posixPath & "Collected-" & jobNumber & "/"
set shellCommand to "find " & quoted form of posixCollected & " -name \"*.zip*\" -exec rm {} \\;"
do shell script shellCommand


-- Move Parent Folder:Collected:Links to Parent Folder:Images and remove Parent Folder:Collected:Links folder
tell application "Finder"
	try
		set CollectedLinks to (folders of entire contents of folder parentFolder whose name is "Links") as alias list
	on error
		set CollectedLinks to (folders of entire contents of folder parentFolder whose name is "Links") as alias as list
	end try
end tell
set posixImages to posixPath & "Images-" & jobNumber & "/"
repeat with aLink in CollectedLinks
	set shellCommand to "mv -f " & quoted form of (POSIX path of aLink) & "* " & quoted form of posixImages & "; rm -rf " & quoted form of (text 1 thru -2 of (POSIX path of aLink))
	do shell script shellCommand
end repeat


-- Move the Parent Folder:Collected:Fonts folder to Parent Folder:
tell application "Finder"
	try
		set CollectedFonts to (folders of entire contents of folder parentFolder whose name is "Fonts") as alias list
	on error
		set CollectedFonts to (folders of entire contents of folder parentFolder whose name is "Fonts") as alias as list
	end try
	make new folder at folder parentFolder with properties {name:("Fonts-" & jobNumber)}
end tell
set posixFonts to posixPath & "Fonts-" & jobNumber & "/"
repeat with aFont in CollectedFonts
	set shellCommand to "mv -f " & quoted form of (POSIX path of aFont) & "* " & quoted form of posixFonts & "; rm -rf " & quoted form of (text 1 thru -2 of (POSIX path of aFont))
	do shell script shellCommand
end repeat


-- Move the Parrent Folder:Collected:InDesign files to Parrent Folder:
set shellCommand to "find " & quoted form of posixCollected & " -name \"*.indd*\" -exec mv -f {} " & quoted form of posixPath & " \\;"
do shell script shellCommand


tell application "Finder"
	-- Send Parent Folder:Comps folder to trash with dialog
	try
		if button returned of (display dialog "Would you like to delete the folder: " & "Comps-" & jobNumber buttons {"Yes", "No"} default button "Yes") is "Yes" then
			move folder (parentFolder & "Comps-" & jobNumber & ":") to trash
		end if
	end try
	
	-- Remove Parent Folder:Copy folder
	set posixCopy to posixPath & jobNumber & "-Copy"
	set shellCommand to "rm -rf " & quoted form of posixCopy
	do shell script shellCommand
	
	-- Send Parent Folder:Reference folder to trash with dialog
	try
		if button returned of (display dialog "Would you like to delete the folder: " & "Reference-" & jobNumber buttons {"Yes", "No"} default button "Yes") is "Yes" then
			move folder (parentFolder & "Reference-" & jobNumber & ":") to trash
		end if
	end try
end tell

Hi aepasieka, James
hope you don’t mind me butting in, and looking at the folder creation script.
I noticed that the creative folk could just as easily put letters in the place of the project numbers and the script would not catch it.
Also I think putting the project number into the default answer is asking for it to be over typed, especially as any text in the default answer is highlighted.

This script should take care of that, (I hope)

property charlist : {"a", "", "b", "", "c", "", "d", "", "e", "", "f", "", "g", "", "h", "", "i", "", "j", "", "k", "", "l", "", "m", "", "n", "", "o", "", "p", "", "q", "", "r", "", "s", "", "t", "", "u", "", "v", "", "w", "", "x", "", "y", "", "z"} --Make a choice for server folder type--
display dialog ¬
	"Select New Project to Start or Cancel Process" buttons {"New Project", "Cancel"}
set the button_pressed to the button returned of the result

--To make  New Project server--
if the button_pressed is "New Project" then
	
	-- Prompt for a sufix.
	set this_itemchar to true
	set the_dialog to "Please enter a job number for the project folder names."
	(* Prompt for a sufix. and check only numbers are entered *)
	repeat until this_itemchar is not true
		set this_itemchar to false
		set sufix to text returned of (display dialog the_dialog default answer "" with icon note)
		set sufixChars to characters of sufix
		repeat with i from 1 to number of items in sufixChars
			set this_itemchar to item i of sufixChars
			if this_itemchar is in charlist then
				set this_itemchar to true
				set the_dialog to "Sorry You Must Only Enter a Number" & return & "Please enter a job number for the project folder names."
				exit repeat
			end if
		end repeat
		
	end repeat
	
	if sufix does not start with "-" then set sufix to "-" & sufix
	
	-- Use a "Save as." dialog to set the name and location for this project folder.
	set parentFolder to (choose file name with prompt "Enter a Folder Name & Pick a Destination, for  job number " & sufix default name ("Enter Folder Name Here")) as string
	
	set parentPosix to quoted form of POSIX path of parentFolder as string
	set sufixChar to (count of characters of sufix) + 1
	
	set thend to characters -sufixChar thru -2 of parentPosix as string
	if thend is not sufix then set parentPosix to quoted form of POSIX path of (parentFolder & sufix as string)
	-- Assemble the mkdir command.
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ""
	set mkdirStr to {"mkdir -p ", parentPosix, "/", "{Comps,Copy,Images,Collected,Reference,PDF}"} as Unicode text
	set AppleScript's text item delimiters to astid
	
	-- Create the folders.
	do shell script mkdirStr
	(* show folder *)
	tell application "Finder"
		activate
		try
			reveal alias (parentFolder as Unicode text)
		on error
			try
				reveal alias (parentFolder & sufix as Unicode text)
			end try
		end try
	end tell
	
end if

LOL, I was bored last night and actually made a AS Studio app that combines both scripts into one and addresses the issues you pointed out above =)

Great minds think alike… and so do ours LOL

Hi James,

Let me first say that you have done more than I ever expected you to do for me. I plan to break down the scripts and learn everything I can from them.

Secondly, I completely agree that putting the project number in the default answer would run the risk of it getting overwritten. So I like what you have done. It’s very easy to run through and leaves no room for error. The only thing is that the project number is not being inserted into the sub-folder structure. My main theory for including the number in the sub-folder structure is that, if there’s an occasion that one of them gets moved accidentally, it can be located by searching for the number and it will eliminate the risk of over-writing other similar folders within another project.

Also, without the project number in the sub-folder names the cleanup script runs into an error were it can’t find the sub-folder without the number. Otherwise, I tested the clean-up script with numbered sub-folders as a suffix and it ran beautifully.

So if the issue of keeping the numbered sub-folders can be fixed then I think everything will work perfectly.

Again, thanks for all the hard work. I’m completely indebted to you.

Alex :smiley:

Alex, check email =)

Nice one james… I got to lean me to use AS Studio one day