Reputation: 13
I wrote a bash script which I turned into an app using Platypus. I chose Platypus so I could easily use the the droplet option.
The basic idea is to take a zip file from the user, unzip the file exclude several of the files we will not use, re-zip the new files and move them to a file on the desktop. When I run the app, the script does not wait for the user to drop a file. It runs and gives an error that no .zip was found.
I have a few questions.
How do I have my app wait for the zip file to be placed on the droplet?
Where does the file get stored by Platypus and how do I call it in the script?
This is what I have so far.
unzip *.zip -x *.cpg *.xml *.txt -d Processed
cd NavtecProcessed
zip -r * *
echo "Cleaning up your mess"
mkdir ~/Desktop/Final/
mv ./*zip ~/Desktop/Final/
sleep 2
cd ..
rm -r NavtecProcessed*
echo "All done!"
The script works when run in the Terminal from the data folder. Any help/guidance would be appreciated.
Upvotes: 1
Views: 899
Reputation: 443
You may have to make some small adjustments to your script in order to make it compatible with the manner in which a Platypus droplet handles dropped files.
Here's the breakdown on how the droplet works:
So the solution to the problem would be to refactor your script to handle the passed arguments. You can do this in bash by using $#
for total number of arguments, and $1, $2, $3
… etc for the rest of the arguments. You can also use $*
to use all arguments.
Here's an example script that will output the file names (in an applescript alert) of the passed files that the droplet sees. Note the if statement that exits if there are 0 arguments passed ($# -eq 0
):
#!/bin/sh
if [ $# -eq 0 ]
then
exit 0
fi
`/usr/bin/osascript << EOT
tell app "System Events"
display dialog "$# argument(s): $*"
end tell
EOT`
As you said, your script currently appears to operate on the folder that you are currently inside of. A simple mod then that perhaps might suite your needs would be:
if [ "$#" -ne 1 ]
then
exit 0
fi
cd $1
unzip *.zip -x *.cpg *.xml *.txt -d Processed
cd NavtecProcessed
zip -r * *
echo "Cleaning up your mess"
mkdir ~/Desktop/Final/
mv ./*zip ~/Desktop/Final/
sleep 2
cd ..
rm -r NavtecProcessed*
echo "All done!"
This script takes a dropped folder, cd's into it, then executes your original script. If there isn't exactly one argument (the folder) passed, then it does nothing.
:) Hope this helps!
Upvotes: 2