scripting file encryption w/ stuffit deluxe in os x

I’m a relative AppleScript novice and could use some help. I’m trying to script the creation of a Stuffit archive with a password/encryption, using Stuffit Deluxe in OS X (10.2.6).

I have the following script, which deletes a file if it already exists, then creates a new archive and then stuffs a specific folder. I want the script to always stuff the same folder and encrypt it with my password. The script works with the critical exception that it doesn’t encrypt the file with a password.

Can anyone help? Is this not possible? Are there any other scriptable applications that could automatically put a password on a file/folder?

Thanks,
Ben


on run
try
tell application “Finder”
delete item “Macintosh HD:Users:MyDirectory:Desktop:archive.sit”
end tell
end try

tell application "StuffIt Deluxe"
	activate
	make new archive with properties {location:file "Macintosh HD:Users:MyDirectory:Desktop:archive.sit"}
	stuff {alias "Macintosh HD:Users:MyDirectory:Desktop:FolderToStuff:"} into archive "archive.sit" password "MyPassword" compression level maximum
	quit
end tell

end run

I tried your StuffIt Deluxe script and it appears to work as expected. What makes you think that the file isn’t encrypted? I was asked for a password whenever I attempted to decompress it.

The reason I think it’s not encrypted is that I’m able to open the stuffit archive created by the script without having to enter a password. I can’t understand why the script won’t work, which seems even stranger now that you tell me the script works for you!

Regards,
Ben

Yes, you can open the archive in StuffIt Deluxe (so can I), but can you actually extract anything without providing a password? :slight_smile:

Yes, it unstuffs the .sit file without asking for a password.

(Normally if you manually encrypt a file it shows a little picture of a lock on all the enclosed files, but there are no locks on the files nor at the top of the archive window.)

Very puzzling. Are you working on OS X 10.2.6 as well, Rob?

-Ben

Yes, 10.2.6, and I just discovered that it isn’t working here either. When I reported success, I had checked the archive that was created when I recorded a similar script. Subsequent tests indicate that the archive is not protected when created by the recorded script. I’d call this a serious bug. I’m so sorry for misleading you. :frowning:

Recent versions of StuffIt Deluxe include command line versions of stuff and unstuff which work quite nicely and they don’t require StuffIt Deluxe to be running. You’ll need to install them since they aren’t installed by default. Check the SD folder for details. These can then be run via AppleScript. Here’s an example of a simple script, and this time I checked to make sure that the resulting archive was password protected. It was. :wink:

set password_ to "MyPassword"
set nameOfArchive to "/Users/me/Desktop/madeFromShellArchive.sit"
set filesNfoldersToStuff to "'/Users/me/Desktop/Test Folder 1' '/Users/me/Desktop/Test Folder 2'"

set stuffCommand to "/usr/local/bin/stuff -p " & password_ & " -n " & nameOfArchive & " " & filesNfoldersToStuff
do shell script stuffCommand

Good luck!

Rob,

Good to know it wasn’t just me having the problem! I’ll have to email Aladdin and let them know about that bug.

Thanks for the info on running Stuffit from the command line. I’ll have to try that out.

Again thanks for your help.

Regards,
Ben

Here’s a more user-friendly script that might be easier to get started with. Feel free to ask questions - I don’t like to run shell commands or scripts unless I know what every little bit means - so I won’t be offended if you ask. :slight_smile:

-- User defined variables.
set password_ to "My Password" --  Replace 'My Password' with yours. Spaces allowed in password
set newArchive to "path:to:new archive.sit" --  Spaces allowed in file/folder names.

-- -- Add as many files/folders to the following list as you like.
set filesNfoldersToStuff to {¬
	"path:to:some:folder:", ¬
	"path:to:some:file", ¬
	"path:to:another:file", ¬
	"path:to:etc"}

-- End user defined variables.

-- Geeks only...
-- Don't change anything below unless you wear a pocket protector.
set unixPaths to ""
set password_ to "'" & password_ & "'"
set nameOfArchive to quoted form of POSIX path of newArchive

repeat with path_ in filesNfoldersToStuff
	set unixPaths to unixPaths & quoted form of POSIX path of path_ & " "
end repeat

set stuffCommand to "/usr/local/bin/stuff -p " & password_ & " -n " & nameOfArchive & " " & unixPaths
do shell script stuffCommand

This works great to “stuff” a file with a password called “My Password”.

Can you let me know how to the “unstuff” that same file using the same password programmatically (using Applescript - without User interaction of entering the password from the keyboard).

That would be an enormous help!
Thanks


--/
set stuffCommand to "/usr/local/bin/stuff -p " & password_ & " -n " & nameOfArchive & " " & unixPaths
do shell script stuffCommand