Re: newbie question: define a variable?
Re: newbie question: define a variable?
- Subject: Re: newbie question: define a variable?
- From: has <email@hidden>
- Date: Sat, 29 Dec 2001 14:22:59 +0000
u7u wrote:
>
variable(w)
[...]
>
setvariable(w = 1)
Arrrr... I see yer not from around these parts then... :)
--
OK... declaring a variable in AS is pretty simple. In fact, you don't have
to explicitly declare a new variable at all (unless you really want to).
For example:
set w to 1
will assign the value 1 to a (local) variable w; if w does not already
exist then AS implicitly declares it for you.
Similarly:
property w : 1
assigns the value 1 to a global variable, w; again the declaration is
implicit. (BTW, you can't use the "property" command within a handler, only
within a script.)
To explicitly declare a new variable, use:
local w
or
global w
--
A few other comments...
Your use of idle and open handlers is also a bit, hmm... shall we say
"eccentric"?;) To clarify these:
Use "on open(listOfFiles)" when you've saved your script as a droplet; when
one or more files are dragged onto its icon, it'll run, with the list of
file(s) being assigned to the variable 'listOfFiles' (or whatever you want
to call it).
Use "on idle" when you've saved your script as a stay-open applet that you
wish to perform a task at regular intervals (the timing can be changed if
desired).
The one I suspect you're looking for is "on run{}", and - guess what? -
it's also declared implicitly by AS, so you don't have to. (The only time
you really need to declare it explicitly is when you want to pass
parameters to the script's run handler.)
All this transparency is great for folks who are being introduced to
programming for the first time through AppleScript as they can just dive
straight in, but can be potentially confusing for those coming from other
languages where explicitly declaring everything up front is the order of
the day. (Equally, AS scripters may get a bit of a shock when meeting
foreign languages for the first time.:)
--
BTW, to windowshade windows - on classic MacOS, at least (I dunno about
OSX, or is that why you've written this script, so you can collapse OSX
Finder windows in-situ?) - use "set window 1's collapsed to true". To
expand them again use "set window 1's collapsed to false". (Note that
setting the bounds to {a,b,c,b+1} doesn't work on classic MacOS.)
So, if I've guessed right, and what you're wanting is a script that can
collapse/expand all Finder windows each time it's run, the following should
do you nicely (for classic; again, I've no idea about X). I've made the run
handler explicit simply for show - you can omit it if you want to.
======================================================================
property w : 0
on run {}
tell application "Finder"
activate
if w = 0 then
set w to 1
-- WINDOWSHADE FINDER WINDOWS
repeat with i from 1 to (the count of windows) - 1
try
set window 1's collapsed to true
on error
end try
end repeat
else
set w to 0
repeat with i from 1 to (the count of windows) - 1
try
set window 1's collapsed to false
on error
end try
end repeat
end if
end tell
end run
======================================================================
This'll give the same effect as option-clicking a windowshade box in the
classic Finder (again, no idea about OSX).
--
Oh, and not forgetting reference materials:
Well, the biggie is the AppleScript Language Guide (which I think is
currently languishing around the AS 1.3.7 mark, though is still mostly
relevant to newer versions). Not sure what the current link to it is (I'm
sure someone else will know).
Here's a tutorial that I rather like:
http://www.mindspring.com/~i_automate/ It's got plenty good information in
very simple, concise form.
HTH
has