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


Click here to return to the 'Open a random file in the GUI via a bash script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open a random file in the GUI via a bash script
Authored by: CkB_Cowboy on Nov 14, '05 08:00:04AM
Here's a much simpler solution:
#!/bin/bash

# Writings location
WritingsPath=~/Public/Downloads

# Writings extensions (delimited by the | char)
WritingsExt='txt|rtf|doc'

find -E "$WritingsPath" -iregex ".*.($WritingsExt)" |
(
	# Put all lines into lines[] array
	i=0; while read line; do lines[i++]="$line"; done
	
	# Open a random lines[] element
	open -e "${lines[$RANDOM % $i]}"
)

---
My ill-matic homepage:
http://rj3.net/cowboy/

[ Reply to This | # ]