I found "find" command is much faster than "Spotlight" in mac os x i rather visualize the results with automator with no luck so I hope geeks around SU will help with solution about that

a shellscript.sh searchphrase executes :

  1. create folder on desktop "Results" if not there

  2. delete everything on this folder (fresh results)

  3. foreach result create a simlink

thank you

link|improve this question
Are you searching for the contents of the file or just the file name? – Jed Daniels Aug 3 '10 at 18:50
feedback

2 Answers

Here's a version with a few improvements.

  • Don't include your user name in the script, use ~ to refer to your home directory.

  • Store the name of the results directory in a variable. This illustrates how to use a variable in a shell script.

  • Make the part that removes the result of a previous search more robust: it won't remove anything that's not a symbolic link.

  • The most important: your version would fail with file names containing spaces or some special characters, because the shell does some reparsing of the result of $(...) and $file. You should always put variable substitutions in double quotes (i.e., write "$file"). My version works correctly with all file names (except if they contain newlines, but that's inescapable with locate).

#!/bin/bash
results_dir=~/Desktop/results
mkdir -p "$results_dir"
find "$results_dir" -type l -exec rm {} +
echo "Please enter some input: "
read -r input_variable
locate "$input_variable" | while read -r line; do
  ln -s "$line" "$results_dir/"
done
link|improve this answer
feedback

my progress:

#!/bin/bash
rm -rf /Users/arpecop/Desktop/results/
mkdir /Users/arpecop/Desktop/results/
echo "Please enter some input: "
read input_variable
for file in $(locate "$input_variable")
do
ln -s $file  /Users/arpecop/Desktop/results/
done
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.