I need help refining Build Order folder script...

Here is my original post…
http://bbs.macscripter.net/viewtopic.php?id=23959

I had tons of help from James Nierodzik the last round.
He was a great help!


(*
 folderStruct v3				James Nierodzik
 Created  2-19-2008		Modified 2-25-2008

For: Casey 'Andrea			kcjones76@gmail.com

-- Expands archive through Archive Utility providing native progress (untested under Tiger)
*)

(*
-- Path Declarations here
set deskpath to path to desktop as Unicode text
set themeFolder to deskpath & "Themes:"
set jobFolder to deskpath & "Jobs:"
--
*)

property themeFolder : missing value
property jobFolder : missing value


set ver to do shell script "sw_vers -productVersion"
if character 4 of ver is "5" then
	set archName to "Archive Utility"
else
	set archName to "BOMArchiveHelper"
end if

tell application "Finder"
	try
		themeFolder as alias
	on error
		display alert "Where is your Life Celebration THEMES folder?" message "We can't find the folder because:" & return & return & tab & "a) this is your first time running this script" & return & tab & "b) the THEMES folder has been moved" & return & tab & "c) the THEMES folder has been renamed" & return & tab & "d) the THEMES folder has been deleted" & return & return & "Please select the Life Celebration THEMES folder" buttons {"Cancel", "Select Folder."} cancel button 1 as warning
		set themeFolder to (choose folder with prompt "Please select the Life Celebration THEMES folder") as Unicode text
	end try
	
	try
		jobFolder as alias
	on error
		display alert "Where is your Life Celebration LIVE folder?" message "We can't find the folder because:" & return & return & tab & "a) this is your first time running this script" & return & tab & "b) the LIVE folder has been moved" & return & tab & "c) the LIVE folder has been renamed" & return & tab & "d) the LIVE folder has been deleted" & return & return & "Please select the Life Celebration LIVE folder" buttons {"Cancel", "Select Folder."} cancel button 1 as warning
		set jobFolder to (choose folder with prompt "Please select the Life Celebration LIVE folder") as Unicode text
	end try
	
	
	set themeList to {}
	try
		set themes to entire contents of folder themeFolder as alias list
	on error
		set themes to entire contents of folder themeFolder as alias as list
	end try
	repeat with aTheme in themes
		set end of themeList to text 1 through -6 of ((name of aTheme's contents) as string)
	end repeat
	
	set orderNum to text returned of (display dialog "Please enter a order number" default answer "")
	set lastName to text returned of (display dialog "Please enter the last name" default answer "")
	set orderName to orderNum & "_" & lastName
	set jobFolderLocation to jobFolder as text
	set theThemeName to item 1 of (choose from list themeList with prompt "Please select the theme for: " & orderName)
	set thetheme to file (themeFolder & theThemeName & ".cpio")
	
	tell application "System Events"
		open thetheme
		repeat
			if (name of processes) does not contain archName then exit repeat
		end repeat
	end tell
	
	set thetheme to folder (themeFolder & theThemeName & ":")
	move thetheme to jobFolder
	set theJob to (jobFolder & theThemeName) as alias
	set name of theJob to orderName
	
	try
		set renameFiles to (every item of entire contents of folder theJob whose name contains theThemeName) as alias list
	on error
		set renameFiles to (every item of entire contents of folder theJob whose name contains theThemeName) as alias as list
	end try
	
	set charCount to count theThemeName
	repeat with aFile in renameFiles
		set oldName to name of aFile
		set name of aFile to orderName & (text (charCount + 1) thru -1 of oldName)
	end repeat
	beep 1
	display alert "Order folder " & (ASCII character 34) & orderName & (ASCII character 34) & " created." message "The order has been placed in the LIVE folder." & return & return & tab & "- " & jobFolderLocation & return & return & "All support files and folders have been renamed to include" & return & "the order number (" & orderNum & ") and last name (" & lastName & ")" & return & return & tab & "For example:" & return & return & tab & "- Folder names, i.e. " & orderName & " Originals" & return & tab & "- File names, i.e. " & orderName & " Tri-Fold.indd" & return & return & "Don't worry about deleting the elements not included" & return & "in the order as they will be purged when archiving." buttons {"OK"} default button 1 giving up after 30
end tell

The basics of the script are as follows:

  1. identifies the folder location of the templates

  2. identifies the destination location for the resulting generated folder structure

  3. builds the theme list based on the contents of folder from Step 1

  4. prompts for an order number

  5. prompts for an last name

  6. creates an order name based on Steps 4 and 5

  7. selects a template from the theme list from Step 3

  8. creates an order folder based on selected template

  9. replaces the theme name with the order name within the filenames of the order folder and all enclosing subfolders/files

The resulting folder is ready to go.
The script works out great, but it turns out the users want to have their cake and eat it too.

An order can contain up to 8 individual products (subfolders)
After the order folder is created the user has to manually delete any products that are not part of that order.

Ideally, the user would be able to specify which products are being used for that order, and delete the rest at the end of the script

Is this feasible?
Can another prompt be presented with checkboxes that would then be used by the script to clean up the order folder?

Am I crossing the realm into AppleScript Studio?
If so, that is even MORE foreign to me and I wouldn’t even know where to start…

In a perfect world, the user could launch the AppleScript or application and be presented with a single dialog box containing all fields, drop-down lists, checkboxes, etc.

Field: Order Number
Field: Order Name
Drop-down list: Theme
Checkboxes: 8 products

Hi KC, unfortunately to do this with any amount of elegance it would require using AppleScript Studio. Otherwise it would just be standard Dialog boxes “Do you want product A? Yes/No” and so on for each product.

AppleScript Studio isn’t very difficult though especially in this sort of scenario where you already have the “meat” of the code done. If you haven’t already download a copy of the developer tools from Apple (they are free) and install them.

I can put together the project for you and send it your way so you can see how it all works. Additionally look thru the examples Apple provides they are great. Also there are some fantastic introduction articles here on MacScripter.

Shoot me an email and I’ll send the project on over to you later today.