A script to open a few images chosen at random
Nov 21, '05 06:21:00AM
Contributed by: xth
When doing design work, I often find I'd like to pick a random picture from my collection as a starting point. So I wrote a simple shell script to do jut that -- once installed, you run it from the Terminal. If you don't like using the Terminal, I have also written a small AppleScript to run it from your desktop. The script can be used to pick randomly from any type of documents within a folder.
Instructions for Terminal installation:
- Download this script to your desktop.
- Open the Terminal (you'll find it in Applications -> Utilities).
- In the Terminal, type sudo -s, then your password when you are asked. Note that this will fail if the user account your are using doesn't have Administrator rights.
- Now type cp ~/Desktop/random_pix /usr/local/bin. The /usr/local/bin folder is a good place to install your personal UNIX scripts.
- Type chmod 775 /usr/local/bin/random_pix (this will make the script executable).
- Text the script by typing /usr/local/bin/random_pix -h; it should display instructions on the command options etc.
- If that works, try typing simply random_pix -h This should display the same output as the previous step. If that doesn't work, type echo $PATH, and scan the Terminal's reply for :/usr/local/bin:. If it's not there, you'll need to add it to your path, as explained in this tutorial.
- If it all works, you can consider customising the script. Double-click on the copy of random_pix on your desktop, and change the 3 on line six to whatever you want the default number of pictures to be, or change the string "~/Pictures" on line seven to wherever you keep your pictures. Lines eight to thirteen provide examples of setting default applications.
- Once edited and saved, switch to the Terminal and type cp ~/Desktop/random_pix /usr/local/bin to place the new script in the right spot.
Read on to see how to run the script from your desktop, as well as ideas for taking it further...
Running the script from your desktop:
If you don't like using the Terminal, it is very simple to run this as a desktop app:
- Open the Script Editor, which you'll find in Applications -> AppleScript.
- In a new document, type the following: do shell script "/usr/local/bin/random_pix"
- Save the document as an Application (using the drop-down menu in the Save dialog) on the Desktop, or wherever you want to keep it.
That's it! You should be able to run the script by double clicking on your new application (it will use the default values).
Taking it further:
You could use this to pick douments of any type and send them to any application, not just pictures, from any directories. The script is simply an interface to the UNIX command find, and it should be easy to add more options to it if you need them -- for example "only pick files of type .mp3" or "only pick files changed within the last 3 days."
[robg adds: This script worked as described for me.]
Comments (1)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20051114083424743