Need help with scripting Stuffit Deluxe 9.0

I am the only Mac tech at my company and was conSCRIPTed to write an Applescript to routinely compress all the folders in a user-chosen folder, each folder going into its own archive. So when the script is done each folder will still be there but there will also be a compressed version with the folder name plus “.sit”.

I’m new to Applescript and I’ve gotten this far with the script:

process_folder(choose folder)

on process_folder(in_folder)
tell application “Finder”
set folder_list to in_folder’s folders
repeat with this_folder in folder_list
tell application “StuffIt Deluxe”
activate
set thisDirName to (get name of this_folder)

			set thisFileName to thisDirName & ".sit"
			make new archive with properties {location:file thisFileName}
			stuff {alias thisDirName} into archive thisFileName compression level maximum
			
		end tell
	end repeat
	tell application "StuffIt Deluxe"
		quit
	end tell
end tell

end process_folder

The problem is with the line beginning with → stuff {alias thisDirName}
I get an Applescript error saying File Alias “folder 123” not found.
Some of this code I got from recording my actions while creating a Stuffit archive and I suspect I may need to explicitly state the path to the current folder, as I get farther when I paste an explicit path after the word alias, with Hard drive name etc.
If anyone could try to replicate this on their OS 10.3.x Mac with a folder containing several subfolders to be archived I would sure appreciate it.
I’m learning as I go along and they want this more sooner than later.

Many thanks in advance

OK, I slogged through your script, fixed some of your mistakes, made a few of my own and came up with this:


process_folder(choose folder)

on process_folder(in_folder)
	tell application "Finder" to set folder_list to in_folder's folders
	repeat with this_folder in folder_list
		tell application "Finder"
			set archiveName to ":" & (name of this_folder) & ".sitx"
			set aliasFolder to this_folder as alias
		end tell
		tell application "StuffIt Deluxe"
			set x to make new archive with properties {location:file (in_folder & archiveName as string)}
			--with timeout of 6000 seconds -- If you have big folders to be stuffed
			stuff aliasFolder into x compression level maximum
			--end timeout
			close x
		end tell
	end repeat
	tell application "StuffIt Deluxe" to quit
end process_folder

If you have any questions, comments, complaints feel free to let’em rip…

Tom

Tom
You are amazing! You hit the nail on the head, the script works perfectly.

thank you for taking time to help me, it really saved me. I would not have been able to do that anytime soon.

Ulysses

Grafux,
I didn’t know that the Finder’s zip function was scriptable, because I tried to do that and when I told Applescript to record my actions and I compressed a folder that way there were no actions recorded in the Applescript editor window. Don’t know why it wouldn’t record those particular actions if it is scriptable.

Tom, I know you have done quite a bit for me but one more thing to ask. The people at work want this also to work across the network on folders on remote servers. So far the script works perfectly on local folders but when I choose a folder that I have linked to on a Windows server I get an error when it comes time to compress the folder. Applescript says there was an error adding files to the archive.

I link to these Windows servers using Connect to Server, with the syntax:

cifs://ourdomain;servermame

and the Windows volume shows up on my desktop like any other server volume. Are there additional path commands that might be needed to make it work on remote folders?

Again thanks for your help.

Finder may feature a method for creating zip files manually but, as far as I can see, the feature hasn’t yet been exposed in its AS dictionary. While it should be possible to access the menu command with UI scripting, the method is a tad clunky - and one which I’d only use as a last resort.

As a ‘quieter’ alternative, you might like to consider using ditto, via a shell script. (In Mac OS 10.4.x ditto will, by default, preserve resource forks and HFS meta-data information when copying. So the explicit ‘–rsrc’ option shown below shouldn’t be necessary in Tiger.)

to zipFolders from mainFolder
	tell application "Finder" to set folderList to name of mainFolder's folders
	set mainPath to mainFolder's POSIX path
	repeat with currFolder in folderList
		set currPath to mainPath & currFolder
		do shell script ("/usr/bin/ditto -c -k --rsrc --keepParent " & ¬
			quoted form of (currPath & "/") & " " & ¬
			quoted form of (currPath & ".zip"))
	end repeat
end zipFolders

zipFolders from choose folder

Just a follow up. Many thanks for tmckenna and you others who replied. The final script is below. It prompts a user to select a folder and then using Stuffit Deluxe to compress each folder in that folder into their own archive, using the folder name plus “.sit” as the name. We need to compress lab data into archives that older Macs using OS 8.6 can extract in the future, as the benchtop Macs are still running the older OS.

It was driving me nuts as it refused to work on remote servers, which is where the data resides. I pinned it down to not working when you connect to Windows servers using SMB or CIFS, but it works like a charm when you connect through Appletalk to Windows servers with Services for Macintosh enabled. I’m using Mac OS 10.3.x and Stuffit Deluxe 8 and 9. I made the Stuffit people at allume.com aware of the bug.

my process_folder(choose folder)

on process_folder(in_folder)
try
tell application “Finder” to set folder_list to every folder of in_folder as alias list
on error – ‘as alias list’ may error!
tell application “Finder” to set folder_list to every folder of in_folder as alias as list
end try
set in_folder to in_folder as Unicode text

repeat with this_folder in folder_list
tell application “Finder”
set aliasFolder to (contents of this_folder)
set archiveName to (name of aliasFolder) & “.sit”
end tell

  tell application "StuffIt Deluxe"
     set x to make new archive with properties {location:file(in_folder & archiveName)}
     --with timeout of 6000 seconds -- If you have big folders to be stuffed
     try
        stuff aliasFolder into x compression level maximum
     on error errMsg number errNum
        log ((errNum as Unicode text) & ": " & errMsg)
        error number -128 -- user cancelled, exit script
     end try
     --end timeout
     close x
  end tell

end repeat
tell application “StuffIt Deluxe” to quit
end process_folder