Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Apple Script:Random File Picker

Apple Script:Random File Picker
Thread Tools
Mac Elite
Join Date: Aug 2006
Location: London
Status: Offline
Reply With Quote
Oct 4, 2006, 07:50 PM
 
Hi Guys

Does anyone know of a way of making a script which opens a random file in a specific folder???


Thanks in advance
Rich
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 5, 2006, 03:37 AM
 
You'd probably want to get every file in the folder as a list, then generate a random number with a maximum of the 'count' of the files - then open the file at index.

something like this:

Code:
tell application "Finder" set targetFolder to choose folder -- or set it via an alias set allFiles to every file of targetFolder set randomFileIndex to (random number from 1 to count of allFiles) open file randomFileIndex of targetFolder end tell
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:37 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2