Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Another way to create Finder-clickable shell scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another way to create Finder-clickable shell scripts
Authored by: trekan on Jul 31, '03 07:37:45AM

The key point is that the path must be absolute. /Users/username/Desktop instead of Desktop and so on.

cd won't help you in a shell script. You must still use absolute paths in the rest of the script. What can save you though is using variables.

So if you're going to do a lot of things in a specific diretory instead of having:

ls /Users/username/sometempdir >> /var/logs/savedfiles.txt
rm /Users/username/sometempdir/*

You can do it like this:

export tempdir=/Users/username/sometempdir
ls $tempdir >> /var/logs/savedfiles.txt
rm $tempdir/*

Remember to include

#!/bin/sh

in the top of the shell script to tell that it should be executed by Bash. I'm not sure other shells support the export command.



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: trekan on Jul 31, '03 07:47:10AM
Oh yeah... if you want to use the script in my example, I would recommend:

#!/bin/sh
export tempdir=/Users/username/sometempdir
export date=$(date +'%Y%m%d-%H%M') ls $tempdir >> /var/logs/savedfiles.txt
tar czf /Users/username/$date.tgz $tempdir rm $tempdir/*

this script creates a tar-gzipped file with the date as the name in the home directory of the user username. It appends the list of files to the file /var/logs/savedfiles.txt and removes the files from the original directory



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: GaelicWizard on Aug 25, '03 12:45:36AM

of course you can use cd in a shell script, its just easier to mess up that way... it is a shell after all! :-D


---
Pell



[ Reply to This | # ]