Solved

Help rebuilding this AppleScript

Posted on 2008-10-15
5
487 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mac Laptop - Water Spill 12 112
El Capitan: danger of a hard restart? 11 80
El capitan screen lock 7 62
Copy multiple iTunes playlists to attached iPod 2 74
Connectivity using SMB Symptoms When connecting to Windows Server shares from a Mac you receive an error similar to "Connection failed because the original item could not be found"Authentication persistently fails to a Windows Server from a Mac wi…
The error "There was an error performing the update" occurred on a Mac OS X client workstation running  Symantec AntiVirus for Mac (http://www.symantec.com/business/products/purchasing.jsp?pcid=pcat_security&pvid=825_1) - the Enterprise product vers…
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 …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

20 Experts available now in Live!

Get 1:1 Help Now