I use Latex to write my documents. Latex creates MANY auxiliary files to compile a document. I often times want to clean my working directory.
When I was working on Windows, I used to keep a .bat file in the working directory that looked like this:
del *.aux
del *.pdf
del *.log
del *.bak
del *.gz
del *.bbl
del *.blg
which I could just click on to get rid of all auxiliary files.
Now, I want to do the same on my Mac. I have created a .sh file like this:
#!/bin/bash
cd `pwd`
echo "Cleaning files..."
rm *.aux
rm *.bak
rm *.bbl
rm *.blg
rm *.gz
rm *.log
rm *.pdf
echo "Done!"
which I know I can run (i.e. invoke from command line), but I cannot click on – which is more convenient because not always I will be using Terminal.
How can I convert this script into a "clickable" one?
I appreciate any input!
Best Answer
Create a text file like this:
Give it a ".command" extension, and add execute permission to it. This will make it automatically open and run in Terminal when it's double-clicked.
Note that there are two important differences (and one minor one) between this and @thiagoveloso's script:
cd
ing to, which will prevent problems if any directory names contain spaces (which is entirely normal on OS X).cd
ing, and if there was a problem it exits (rather than deleting files in an unexpected location). Always check for errors on any script command that affects what the rest of the script will do;cd
is a good example of this.cd
s directly to the script's directory (rather thancd
ing there, capturing that location in a variable, thencd
ing there again based on the variable).