Help rebuilding this AppleScript

I inherited a VERY convoluted AppleScript we using during our archiving procedures using an older OS X 10.3 machine with a VERY specific configuration. When I've tried to run this script on another machine - I received an error referencing a portion of the code that uses a function called <<WaynTkii>>. Through a little digging I discovered that this is an ACME Script Widgets tokenize function (I think). After trying to get ACME Script Widgets to run on a 10.5 and 10.4 machine - I gave up after receiving the same error.

Furthermore - I'm not 100% sure what the script does. I do know that it goes through each folder to be archived and removes an underscore and all text thereafter in the folder names, and seems to be moving some files/folders around within that folder, but nothing specifically.

Can anyone take a look at this and rewrite it will run without depending on ACME Script Widgets - and hopefully on OS X 10.5. Code to follow



on open archive_root
	global folder_name, folder_num, job_num_list, job_name_list, other_folder_name, other_folder_num, old_job_number, this_job_number, folder_number
	set archive_root to archive_root as text
	with timeout of 600 seconds
		tell application "Finder"
			set folder_list to the name of every folder of folder archive_root as list
			set volume_name to (the first item in («event WaynTKii» archive_root given «class SEPl»:":")) as text
			try
				make new folder at disk volume_name with properties {name:"TEMP"}
			end try
			
			set folder_count to the count of items in folder_list
			
			set job_num_list to {}
			set job_name_list to {}
			
			repeat with this_folder from 1 to folder_count
				set folder_name to (item this_folder in folder_list) as text
				set this_job_number to (the first item in («event WaynTKii» folder_name given «class SEPl»:"_") as text) as text
				if (job_num_list contains this_job_number) then
					set list_offset to the «event WaynFINL» job_num_list given «class ForS»:this_job_number
					set other_folder_name to (item list_offset in job_name_list) as text
					activate
					beep 2
					display dialog ("The following folders are the same job #" & return & folder_name & return & other_folder_name) with icon 2
					display dialog "Name for folder" & return & folder_name default answer folder_name with icon 1
					set folder_num to the text returned of result as text
					display dialog "Name for folder" & return & other_folder_name default answer other_folder_name with icon 1
					set other_folder_num to the text returned of result as text
					set job_num_list to («event WaynRPLC» this_job_number given «class in  »:job_num_list, «class with»:other_folder_num) as list
					copy folder_num to the end of job_num_list
					copy folder_name to the end of job_name_list
				else
					copy this_job_number to the end of job_num_list
					copy folder_name to the end of job_name_list
				end if
			end repeat
			
			repeat with thiss_folder from 1 to folder_count
				set folder_name to (item thiss_folder in job_name_list) as text
				set folder_number to (item thiss_folder in job_num_list) as text
				set old_job_number to (the first item in («event WaynTKii» folder_name given «class SEPl»:"_") as text)
				try
					set the name of folder (archive_root & folder_name & ":" & (old_job_number & "_FONTS") as text) to (folder_number & "_FONTS")
				end try
				set the name of folder (archive_root & folder_name) to folder_number
			end repeat
			
			set folder_list to the name of every folder of folder archive_root as list
			set folder_count to the count of items in folder_list
			
			repeat with this_folder from 1 to folder_count
				set folder_name to (item this_folder in folder_list) as text
				set this_job_number to (the first item in («event WaynTKii» folder_name given «class SEPl»:"_") as text)
				try
					make new folder at folder (volume_name & ":TEMP:") with properties {name:folder_name}
				end try
				if folder (archive_root & folder_name & ":Control:") exists then
					move folder (archive_root & folder_name & ":Control:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
				if folder (archive_root & folder_name & ":Fonts:") exists then
					move folder (archive_root & folder_name & ":Fonts:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
				if folder (archive_root & folder_name & ":HotFolders:") exists then
					move folder (archive_root & folder_name & ":HotFolders:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
				if folder (archive_root & folder_name & ":System:") exists then
					move folder (archive_root & folder_name & ":System:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
				if folder (archive_root & folder_name & ":WebDownloads:") exists then
					move folder (archive_root & folder_name & ":WebDownloads:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
				if folder (archive_root & folder_name & ":WebUploads:") exists then
					move folder (archive_root & folder_name & ":WebUploads:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
				if folder (archive_root & folder_name & ":VPS-Sigs:") exists then
					move folder (archive_root & folder_name & ":VPS-Sigs:") to folder (volume_name & ":TEMP:" & folder_name & ":")
				end if
			end repeat
			beep 2
			display dialog "Folder Moves Completed" with icon 1
		end tell
	end timeout
end open

Open in new window

LVL 1
weirdturnedproAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
weirdturnedproConnect With a Mentor Author Commented:
After a lot of research online and a good AppleScript in a nutshell book, I have a solution that seems to work. Code to follow. Sorry I didn't get back sooner and post a before and after directory comparison - while helpful, this may have been extremely lengthy due to the number of files involved in the transaction. However, if anyone has suggestions for improving the posted code to follow - I'd be appreciative (always good to have a second opinion).
#!/bin/bash
#init
 
#Define functions
function pause(){
	read -p "$*"
}
 
#Define variables
arvol=/Volumes/trnsfrdrv
strvol=$arvol/strip
 
@echo off
clear
 
echo "Checking for Required Volume..."
if
	[ -d $arvol ]
		then echo "OK"
	else
		echo "Volume Not Connected!"
		exit
fi
 
cd $strvol
 
echo "Cleaning Folders for Archive..."
for i in *
	do mv "$i" "${i/_*}"
done
 
echo "Moving Exported Archive to Root Folder..."
for z in *
	do mv $strvol/$z/UserDefinedFolders/Exports/*.zip "$strvol/$z/$z.zip"
done
 
echo "Removing Unneeded Folders..."
for r in *
	do rm -r "$strvol/$r/UserDefinedFolders/Exports/"
	rm -r "$strvol/$r/UserDefinedFolders/WORKERS_DELETE/"
	mv $strvol/$r/UserDefinedFolders/*FONTS/ "$strvol/$r/UserDefinedFolders/FONTS/"
	mv $strvol/$r/ $arvol/transfer/$r/
done

Open in new window

0
 
dsclCommented:
If you could provide a example of a folder layout pre script run and post script run it would make our lives much easier in doing the re-write.
0
 
James LooneySr. Programmer/AnalystCommented:
So does this new shell script not do what you need it to? If not, what is it not doing?
0
 
weirdturnedproAuthor Commented:
After a full week of testing it seems to be doing everything I need it to do; I just wanted another set of eyes to look it over. I've revised it a little bit since, but the core foundation seems to be effective.
0
 
James LooneySr. Programmer/AnalystCommented:
Ya, with just your original description, it seems reasonable.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.