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 > Developer Center > Open Random File in a Folder

Open Random File in a Folder
Thread Tools
JamesKass
Junior Member
Join Date: Nov 1999
Location: E. Brunswick, NJ USA
Status: Offline
Reply With Quote
Dec 31, 1999, 06:53 PM
 
I'm for a script that will open a random file within a specified folder. (For example, say I have a folder that contains several sound files, and I'd like to play a random one each time the script is ran.) Any Suggestions?

------------------
James Kass (no, the other one...)
[email protected]
http://members.home.net/kassj
James Kass (no, the other one...)
[email protected]
http://NYComedyRadio.com :)
     
RGS
Guest
Status:
Reply With Quote
Jan 1, 2000, 10:34 AM
 
Here are a couple of sample scripts that might help you accomplish your goal. They require the scripting addition (also known as osaxen) "Jon's Commands".

For my example, I created a folder named "Sounds Folder" on the startup disk and copied all the sound files from the System to it. Feel free to tweak as you see necessary.

-- Script 1 --

set sound_folder to (path to startup disk as string) & "Sounds Folder"

set sound_list to list folder sound_folder

set sound_count to number of items in sound_list

set random_number to random number from 1 to sound_count

set my_sound to item random_number of sound_list

play sound my_sound

-- End Script 1 --


-- Script 2 --

set sound_folder to (path to startup disk as string) & "Sounds Folder"

set sound_list to list folder sound_folder

set my_sound to some item of sound_list

play sound my_sound

-- End Script 2 --
     
mikebat
Fresh-Faced Recruit
Join Date: Oct 1999
Location: Wellington, New Zealand
Status: Offline
Reply With Quote
Jan 1, 2000, 07:44 PM
 
This script uses the "some" keyword in AppleScript to select a random file in the System Folder.

Change "select" to "open" and "system folder" to (for example)
folder "Sounds" of startup disk

--start of script
tell application "Finder"
select some file of system folder
end tell
--end of script
     
JamesKass  (op)
Junior Member
Join Date: Nov 1999
Location: E. Brunswick, NJ USA
Status: Offline
Reply With Quote
Jan 7, 2000, 11:11 PM
 
Tried the "some", seemed to work... however...

Is there any way to make it more random? It always plays the songs in the same order each time the script is run. Any suggestions?

------------------
James Kass (no, the other one...)
[email protected]
http://members.home.net/kassj
James Kass (no, the other one...)
[email protected]
http://NYComedyRadio.com :)
     
QuatermassX
Forum Regular
Join Date: Oct 1999
Location: London
Status: Offline
Reply With Quote
Jan 7, 2000, 11:18 PM
 
tell application "Appearance"
set picture file of monitor 1 to alias "Macintosh HD:System Folder:Appearance esktop Pictures:"
set picture positioning of monitor 1 to automatic
quit application "Appearance"
end tell

This is an AppleScript I picked up somewhere on the web. You can modify it quite simply for other sorts of media.

Have fun!!
     
QuatermassX
Forum Regular
Join Date: Oct 1999
Location: London
Status: Offline
Reply With Quote
Jan 7, 2000, 11:21 PM
 
PS. All the Desktop Pictures need to be loose in whatever directory you choose to serve as the "Random Bin". Aliases work just as well for me.
     
   
 
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
Top
Privacy Policy
All times are GMT -4. The time now is 12:59 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,