Re: Idle Help
Re: Idle Help
- Subject: Re: Idle Help
- From: Phi Sanders <email@hidden>
- Date: Wed, 6 Dec 2000 22:16:12 -0500
globals do not remember their settings from the last run,
properties do (unless you recompile them, then they start
fresh on the first run after the recompile)
~Phi
--
Phi Sanders
"Phee, Phi, Pho, Phum..."
On 12/6/00, Byron Peterson {email@hidden} said the following :
>
>Byron Peterson wrote:
>
>
>
>> How do I pass variables from the 'run' section to the 'idle' section
>
>> without using 'global' or 'property' statements.
>
>>
>
>> ie.
>
>>
>
>> on run
>
>> set test to "Hello World!"
>
>> end run
>
>>
>
>> on idle
>
>> display dialog test
>
>> return 10
>
>> end idle
>
>
>
>You don't. I realize that you may have had "Globals Are Bad" burned
>
>into your brain in an introductory programming course, but the reality
>
>is that sometimes there's no other way. This is one of those times.
>
>
>
>The difficulty is that "run" and "idle" are independent entry points
>
>into your script that are called from the outside, i.e., the applet
>
>shell. In order to share information between them, you have to put it
>
>somewhere both handlers can see, and that means a global or property of
>
>some sort.
>
>
>
>If it really bothers you, you can compartmentalize the offending globals
>
>by putting them inside a script object, like this:
>
>
>
> script messages
>
> property hello : ""
>
> end script
>
>
>
> on run
>
> set hello of messages to "Hello world!"
>
> end
>
>
>
> on idle
>
> display dialog hello of messages
>
> end
>
>
>
>If there's only one global, this technique is mostly a waste of time,
>
>but if you have lots, and they fall into clear groups, then it's a good
>
>way to keep them separate.
>
>
>
>
>
>--Chris Nebel
>
>AppleScript Engineering
>
>
>
OK, let me break down the problem I am having and maybe you can help.
>
I have written a script to change the desktop picture at a set
>
interval. The script has support for two monitors and the ability to
>
alternate back and fourth between them. I read the picture files
>
from a folder (as well as from sub folders) into a list (this happens
>
during the run stage). I then get a random number (1 to total number
>
of items in the list) and display that image on either monitor 1 or 2
>
(whichever is next) using the appearance manager during the idle
>
stage. After I select an image, I remove it from the list (so that
>
the same picture won't be displayed again until all pictures have
>
been displayed). After the list reaches 0, I then re-read the
>
picture files back into the list and start the process over. The
>
problem I am having is it isn't random at all. After a computer
>
restart, it starts with the same picture every time,then goes to the
>
same second picture and so fourth. I have looked and looked for the
>
problem but it doesn't appear to be how I get the random number.
>
Below is the code that gets the random number.
>
>
set listTotal to the count of desktopPictures
>
set randomNumber to random number listTotal from 1 to listTotal
>
>
The only thing that I have found is a brief comment somewhere (I
>
don't remember where) that states the variables carry their values
>
across restarts when you use global or property settings. I am new
>
to applescript and really don't understand how (and when) to use
>
global variables or property variables and exactly what there overall
>
effect is. If anybody can give me some good insight, I would
>
appreciate it.
>
>
Thanks,
>
>
BJ
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users