I have a mail attachement with the extension .gem, and I would like to use that attachement as the argument to a java .jar program.
I've figured out how to start the java program using a shell script like this:
#!/bin/bash
java -jar /Users/geoff/Programs/program.jar $1
If I name this script program.sh and change the permissions to allow execution, I can successfully run the program by typing this in a terminal window:
./program.sh filename.gem
However, when I try to open the attachement filename.gem from mail, it won't let me use program.sh to open the attachment. The OS seems to make a distinction between a file and an application that is independent of the execute permission on the file.
After doing some reading about this, I tried Automator. One of the Automator actions is to execute a shell script, so I added that action to my Automator project and typed in my command: java -jar /Users/geoff/Programs/program.jar $1
I also changed to input from options from "stdin" to "argument".
I then saved the Automator project, and was able to associate that project with the .gem file attachement from mail. The java program started, but behaved as if the $1 argument was not included.
If this is making sense to anybody, do you have any suggestions? (Perhaps I just need to leave out the "$1" in my Automator command, trusting Automator to insert the argument in the proper place. If that theory is correct, my program is interpreting the text "$1" as an argument, which would be consistent with the behavior that I'm seeing.)
I've seen other suggestions to use AppleScript, but it seems to me that there ought to be some simple way to do this.
(I just got a Mac, by the way. I was able to do this in Windows using MIME type definitions and a .bat file. The difference is that Windows allowed me to consider program.bat as an executable, but Mac OS doesn't consider program.sh to be an executable.)
Thanks a lot.
Geoff
I've figured out how to start the java program using a shell script like this:
#!/bin/bash
java -jar /Users/geoff/Programs/program.jar $1
If I name this script program.sh and change the permissions to allow execution, I can successfully run the program by typing this in a terminal window:
./program.sh filename.gem
However, when I try to open the attachement filename.gem from mail, it won't let me use program.sh to open the attachment. The OS seems to make a distinction between a file and an application that is independent of the execute permission on the file.
After doing some reading about this, I tried Automator. One of the Automator actions is to execute a shell script, so I added that action to my Automator project and typed in my command: java -jar /Users/geoff/Programs/program.jar $1
I also changed to input from options from "stdin" to "argument".
I then saved the Automator project, and was able to associate that project with the .gem file attachement from mail. The java program started, but behaved as if the $1 argument was not included.
If this is making sense to anybody, do you have any suggestions? (Perhaps I just need to leave out the "$1" in my Automator command, trusting Automator to insert the argument in the proper place. If that theory is correct, my program is interpreting the text "$1" as an argument, which would be consistent with the behavior that I'm seeing.)
I've seen other suggestions to use AppleScript, but it seems to me that there ought to be some simple way to do this.
(I just got a Mac, by the way. I was able to do this in Windows using MIME type definitions and a .bat file. The difference is that Windows allowed me to consider program.bat as an executable, but Mac OS doesn't consider program.sh to be an executable.)
Thanks a lot.
Geoff