Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript "some" keyword

This Applescript line


open some file of folder "[folderPathName]"


displays a random-choice jpg from a folder containing only jpgs, and works well – except that it always chooses the same “random” files, starting with one particular file and then going through the exact same sequence of “random” selections every time.


Restarting the Mac resets the sequence. The first time this line is called after a restart, it begins with that same first “random” selection and goes through the same sequence.


Am I misundersanding the some keyword? Does it need a “seed” to make it fully random?


Thank you.

Posted on Oct 11, 2012 7:08 AM

Reply
7 replies

Oct 11, 2012 4:05 PM in response to LongRiver

Thank you.


As far as I can tell, some will return the same sequence of "random" numbers starting with its first call after a system startup.


So random number seems needed. It can work from a seed.


This example isn't fully random, since the seed, current date, changes only once a second, but for many purposes that's good enough:


set n to random number from 1 to (count of [aFolder]) with seed (seconds of (current date))

Oct 13, 2012 7:25 AM in response to LongRiver

FIrst, try resetting the PRAM. As far as I can think, the most likely cause of this effect would be that the system is seeding its random number generator with the exact same 32/64-bit integer at startup. That speaks to something being off at a very low level, which a PRAM reset might shake loose.


If that doesn't solve the problem, could you explain precisely what you do to make this happen - i.e., give us the whole script (it it's not too long) and tell us how and when it gets launched? There are only three other ways I can think of to get this effect, and they are all far-fetched:


  1. You run this applescript so early in the startup process that the system hasn't been fully initialized.
  2. You've added a bad or outdated third-party scripting addition that's interfering with the way applescript works.
  3. You're running the command in a context that has (somehow) redefined the some keyword.


I'm betting on the PRAM thing, though, because everything else is a bit crazy.

Applescript "some" keyword

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.