Automatic scrolling
Automatic scrolling
- Subject: Automatic scrolling
- From: Mr Tea <email@hidden>
- Date: Tue, 19 Feb 2002 01:04:25 +0000
Hi.
On the AppleWorks list recently, a severely handicapped contributor wrote
in to ask about ways of scrolling a document automatically...
>
I use to have a program which simulated
>
a mouse click every two seconds. When sick,
>
I'd have someone load an e-text, put the
>
mouse over the down arrow and every two seconds
>
the mouse would click and scroll up a new line.
Was there, he asked, a way to do something similar with AppleWorks &
AppleScript...
Well, I couldn't find a way to make AW scroll gracefully, a line at a
time, but I knocked together a script droplet that uses Tex-Edit Plus to
do the job. Before I go submitting my wonky, pitfall-ridden,
spit'n'sawdust efforts to some poor geezer in his sick-bed, I wanted to
seek out some advice on how to tidy up the script and make it reasonably
SNAFU-proof. I'd also be interested to hear about any alternative ways of
approaching this issue that spring to the gestalt mind of the list. I've
put this together and tested it in OS X (AS 1.8.2b1), but it is destined,
in this specific case, for a machine running 8.6. The droplet is named
"Scroll in Tex-Edit"
Here's the script...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on open theBookList
repeat with theBook in theBookList
tell application "Finder"
open theBook
end tell
(*
The next section finds out which app the target file opened in
and sets the comment of the applet. This latter action is there
to prep the applet so that it can be controlled by a second script
in the Speakable Items folder.
*)
tell application "Finder"
set theAppList to application file of [option+return]
(every application process whose frontmost is true) as alias
set theFrontApp to item 1 of theAppList
set theScroller to path to me as alias
set comment of theScroller to "1"
set theType to creator type of item 1 of theAppList
end tell
(*
This next bit is a sort of modular thingy, and could probably
be put into a handler - I would like to expand this section so
that the droplet can handle documents in any format that applescript
can copy the text out of. I wanted to use a variable (theFrontApp) in the
'tell application...' line, just in case the app's name had
been changed, but the script wouldn't have it, regardless of whether
I stored just the name of the application or an alias pointing directly
at it in the variable. I just got Endless error messages like [can't get
application "AppleWorks 6" of <<script>>] and [can't set blah-di-blah
to every text of blah-di-blah]. (All of that will probably change when I
move over OS 9, I would imagine.) Also, I couldn't get the standard
additions 'set the clipboard to' command to work in this block,
and I have no idea why. The clipboard just stayed blank. The section is
wrapped in a 'considering' block, because I found that the script was
sometimes moving onto the next section before AppleWorks had selected
or copied any text.
*)
if theType is "BOBO" then
considering application responses
tell application "AppleWorks 6"
set selection to text of document 1
copy to clipboard
close document 1
end tell
end considering
end if
(*
Nearly there, now. The first 'if' block won't run if the dropped document
is already open in Tex-Edit Plus. The scrolling is made to work by selecting
the first character of each line in turn. I wanted to just move the
insertion
point, but couldn't figure out the syntax for that. (The delay will probably
be longer in the 'finished' script, if it comes to that.) In the repeat
loop,
scrolling can be paused by running another script that changes the
comment of
the running applet. I'm wondering if the same sort of thing could be
achieved
with, um, a property or something, but I'm a bit out of my depth there.
*)
tell application "Tex-Edit Plus"
activate
if theType is not "TBB6" then
make new window with properties {bounds:{10, 50, 600, 736}}
paste
end if
set theCount to count of lines of window 1
set LL to 1
repeat until LL = (theCount + 1)
select character 1 of line LL of window 1
delay 1
tell application "Finder" to set theScrollControl to comment of
theScroller
if theScrollControl is "1" then set LL to LL + 1
end repeat
delay 30
close window 1 saving no
end tell
end repeat
end open
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you've made it this far, thanks for wading through. I suspect that the
script needs some error trapping built in to cope with documents that
don't play nice, and I'm not sure about that 'repeat until' loop, which
could go on forever if scrolling is paused. I've gone about as far as my
AS skills will take me with this, so any input would be very welcome. For
completeness sake, here is the script that 'pauses' the scrolling effect.
Again, it's not exactly bulletproof:
tell application "Finder"
set theAutoScroller to file of (every process whose creator type is
"dplt") as alias
if comment of theAutoScroller is "1" then
set comment of theAutoScroller to ""
else
set comment of theAutoScroller to "1"
end if
end tell
Cheers
Mr Tea
--
"Always remember to warm the pot."
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.