Solved

Help rebuilding this AppleScript

Posted on 2008-10-15
5
488 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:weirdturnedpro
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dscl
ID: 22731705
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
 
LVL 1

Accepted Solution

by:
weirdturnedpro earned 0 total points
ID: 22745958
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
 
LVL 6

Expert Comment

by:James Looney
ID: 22839756
So does this new shell script not do what you need it to? If not, what is it not doing?
0
 
LVL 1

Author Comment

by:weirdturnedpro
ID: 22841234
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
 
LVL 6

Expert Comment

by:James Looney
ID: 22841486
Ya, with just your original description, it seems reasonable.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mac OSX can't search on smb  via finder 10 189
Upgrading Mac Mini Server to Sierra 5 518
MAcbook and iPAd Pro 5 65
apache vhosts on mac not being recognized 5 80
We could spend the next millennium discussing the differences of the Mac and Windows platforms. The next century will continue to have fanatics on both side of the equation and neither side will win the war. However, that’s not why we are here. W…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now