Link to home
Start Free TrialLog in
Avatar of weirdturnedpro
weirdturnedpro

asked on

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

Avatar of dscl
dscl

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.
ASKER CERTIFIED SOLUTION
Avatar of weirdturnedpro
weirdturnedpro

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So does this new shell script not do what you need it to? If not, what is it not doing?
Avatar of weirdturnedpro

ASKER

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.
Ya, with just your original description, it seems reasonable.