I have a shell script that run flawlessly when run from terminal
sh script.sh [name_of_the_pdf_.pdf]
The script read the filename of a given .pdf and set some variables from the filename first characters:
For instance, the following variable reads the first two characters from the filename and stored them as a variable:
VAR_ENDPAGE=${1:0:2}
Then the script runs a java program from the command line passing arguments from these stored variables:
java -jar jpdftweak.jar -i7-"${VAR_ENDPAGE[@]}" $1 -output ~/OUTPUTFILE.pdf
Assuming [name_of_the_pdf.pdf]=2350.pdf
the resulting command would be:
java -jar jpdftweak.jar -i7-23 $1 -output ~/OUTPUTFILE.pdf
The problem is when I use this script in Platypus. I created a Droplet, and when I drop the "2350.pdf" file the program runs the script using this file as $1
argument. All seems to be fine, but it seems to be unable to create properly the variables. For instance, the above variable returns: /U
, so the command is:
java -jar jpdftweak.jar -i7-U/ $1 -output ~/OUTPUTFILE.pdf
The script is exactly the same. So the error is in the variable setting process. I tried using backticks, but anything seems to work…
Where does this U/
come from?
Well, a friend give me an advice… and solved it.
The problem was: in the Terminal, the file only had name and extension, but when launching the droplet, the file will contain also the path, located at /Users/etc… The script will load the first two characters from the filename, but in the droplet the filename started with the path, so this give me that "/U" error "/U"sers… etc.
Script corrected, and running!