Re: idle() loops & command-keys
Re: idle() loops & command-keys
- Subject: Re: idle() loops & command-keys
- From: JJ <email@hidden>
- Date: Fri, 12 Oct 2001 12:57:09 +0200
>
I'd like to make my currently menu driven script (choose from list) -
>
just a tad more friendly by allowing it to bring up the menu dialog from
>
a key combo (command-N for example)
>
>
It seems like I'd save it as stay open and have an idle loop look for the
>
key event...
>
is there any way to do this? or any approach that is roughly equivalent?
>
>
I've got some script objects in memory that I want to be persistent, but
>
I need to allow the user to switch off to other apps as well - hence the
>
request.
You could try using Dialog Director & Jon's Commands, and you wouldn't need
idle loops. Try this test script:
-- STARTS SCRIPT
set theD to {size:{200, 70}, style:standard palette, closeable:false,
default item:0, name:"Menu", contents:{(opt+L)
{class:push button, bounds:{2, 3, 82, 23}, name:"Open O"}, (opt+L)
{class:push button, bounds:{2, 25, 82, 45}, name:"Close W"}, (opt+L)
{class:push button, bounds:{2, 48, 82, 68}, name:"Quit Q"}, (opt+L)
{class:static text, bounds:{90, 27, 190, 43}, contents:"Hit me!"}}}
-- The "Command" string is ASCII character 17
dd install with fonts {name:"Charcoal", size:12, color:{65535, 65535, 0}}
float above every application with grayscale given +class Tint;:[60, 86,
147]
-- font color: RGB 0-65535
-- dialog color: RGB 0-255
-- SO BEAUTIFUL DIALOG
set d to dd make dialog theD
try
repeat while (keys pressed) {"Q", "Command"} -- Jon's Commands
set k to dd interact with user for max ticks 1
-- loops every 1 ticks (1/60 seconds)
if k = 1 or (keys pressed) = {"O", "Command"} then
dd set contents of d's item 4 to "Opened!"
else if k = 2 or (keys pressed) = {"W", "Command"} then
dd set contents of d's item 4 to "Closed!"
else if k = 3 then
exit repeat
end if
end repeat
on error
end try
dd uninstall
-- ENDS SCRIPT
Dialog Director's environment offers you, too, two additional & free
shortcuts, if you define a default item (must be a button):
- Enter & return: if a button, executes default item.
- Esc & "Command+.": executes first non-default button or maps to "Cancel"
button.
It works for me (OS 8.6, pretty purple iMac).
(opt+L) is (opt+6) here.
JJ