Well, there are several problems with your script. It would help if you posted what error message you were getting since it's not clear which problem is tripping you up.
For one:
set fileAlias to the selection as alias
This always returns a list. Even if there's just one item selected (you get a list of one item). You need to decide how you want to deal with that. Do you want to combine each file into one .zip archive? create one archive per file? something else?
Even more bizarrely you're asking the Finder for the
selection, even though you're in an
open handler that's passed a list of files. Which do you want? Do you want to compress the selected items? or the items dropped on the app icon?
Secondly:
set theDirectory to "cd" & theItems
Well,
theItems is a list of items dropped on the app. I'm not sure what use there is in creating a new text object that combines the characters 'cd' with the paths of the dropped files, especially since you don't actually use this variable at an other point in your script.
Then:
set shellcommand to "zip -e" & " " & fileName & ".zip" & " " & fileName & "password" & return & "password" & return
This makes no sense. For one, according to
man zip, -e tells zip to encrypt the archive using the password that it prompts for. There's nothing that tells it to take a password from the command parameters. Even if it did your string concatenation is off, particularly:
... & fileName & "password"
Assuming fileName was 'some.html" (which it won't be, but just go along with it for now), this will result in "some.htmlpassword". There's no way that's right. At the very least there should be a space preceding the 'password' string, so you'd end up with "some.html password", but that still doesn't make much sense given the fact that zip doesn't take a password from the command line parameters anyway.
Then there's:
& return & "password" & return
You cannot embed return characters in a shell command like this.
and finally, for now:
set result to do shell script shell command
You're using
do shell script which executes the command directly. So why is this in a
tell application "Terminal" block? Nothing here requires the use of Terminal.app, except, maybe, for prompting for the encryption password. If you want to use Terminal.app to run this then use
do script rather than
do shell script.
So all in all it's not surprising that your script doesn't work 🙂
There are some clarifications needed regarding which file(s) to action before anyone can provide a solution.