• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is there a way to keep a floating window open?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to keep a floating window open?


  • Subject: Re: Is there a way to keep a floating window open?
  • From: kai <email@hidden>
  • Date: Fri, 6 Jan 2006 17:25:55 +0000


On 5 Jan 2006, at 19:40, David B. Gustavson wrote:

Thanks, Kai!
This is exactly what I needed.

No worries, Dave. Sorry (again) for the delayed response - heavy commitments elsewhere, I'm afraid.


I did use Growl meanwhile, and it kind of works, but had cosmetic problems like the window size being too small for some of the lines I wanted displayed so they wrapped awkwardly, and there was no way to change that that I could find.

Your solution has the advantage of not needing any non-AppleScript extra stuff. It would be nice if it could install its helper app itself, but saving a script app in Applications isn't hard to document for a manual install.

One might have hoped that 'store script' (Standard Additions: Scripting Commands) would do the trick. However, that seems rather limited - compared, that is, to the wider choice of save options currently available. (OMM, it doesn't seem to be 100% reliable, either.)


Nevertheless, just to give you the flavour, this should save a simple script to the desktop:

-----------------

script to_store
	display dialog "Hello world."
end script

set file_path to (path to desktop as Unicode text) & "Store Script Demo.app"
store script to_store in file_path


tell application "Finder" to open file_path (* test it *)

-----------------

Unfortunately, if you want to create a stay-open app, there doesn't appear to be a simple way - short of messing with plist and resource files, etc. One way around this might be to use Script Editor. Not the most visually elegant approach, granted - but it would certainly spare the user having to worry about it. (I've included an example below.)

Thank you very much, and also for the explanatory material you included.

Is there a way to control or affect the position of the display dialog, or to put something in its title bar?

If you're using Tiger, you can add text to the title bar of a dialog box. The example in my previous post would then need to be modified along these lines:


-----------------

to show_message(title_text, message_text, view_time)
activate
display dialog message_text buttons {"OK"} default button 1 ¬
with title title_text giving up after view_time
if view_time is 0 or view_time > 60 then return quit
tell application "System Events" to set process "Message"'s visible to false
end show_message


-----------------

While it's not possible (AFIK) to change the initial position of a dialog, we could try jumping on it the moment it appears - and drag it (probably a-kickin' and a-hollerin') to our chosen spot. Again, not exactly subtle, but it might suffice for your purposes.

Bearing in mind what we discussed earlier (regarding the modal nature of dialog boxes), any movement of the dialog window should be carried out by the calling script - rather than from within the applet (which will only confuse itself). So the calling routine might now look something like this:

-----------------

set title_text to "Your Mac Speaks Up"

set message_text to "Mac OS X Tiger includes a variety of accessibility features. The most vocal of these features is VoiceOver, which offers visually impaired individuals magnification options, keyboard controls and a spoken English description of what’s happening on screen. VoiceOver can read web pages, Mail messages and word processing files. And it’s available out of the box. Just press Command-F5 for the VoiceOver QuickStart."

ignoring application responses
	tell application "Message" to show_message(title_text, message_text, 5)
end ignoring

tell application "System Events" to tell window 1 of process "Message"
	repeat until exists
		delay 0.1
	end repeat
	set position to {0, 22}
end tell

-----------------

Incidentally, Tiger's new display alert command offers an attractive alternative for separating a main opening statement from more detailed text - since it presents a message in two different font sizes/styles. Scripting details can be found in the User Interaction suite of the Standard Additions dictionary. (Apologies if you're pre- Tiger - in which case you may have to forgo titles for the moment.)

One more point, just in case you're considering having the same script install the helper app - and then follow right on with various dialog calls. What's really needed here is some way to break up the two operations - otherwise you may find yourself running into some quite nasty timing issues (especially with the initial dialog). Most of the usual fixes (delays, Finder updates, etc.) probably won't help much here, either - so I'd normally have suggested a separate install operation. However, there's still one separating device that should work: a dialog. (Quite handy at this point, since it's generally considered courteous to consult the user on an install, anyway.)

Finally, it occurred to me that this approach might occasionally be prone to problems, should a dialog still be present when the next one turns up - if a glitch, for example, prevents dismissal of the earlier one, or timing variations cause an unexpected overlap. Anyway, I've added a short routine below to force an older dialog to yield to a newer one. (It can easily be removed to reverse the priority.) You should be able to test this by prematurely retriggering the script below (obviously after the install part of the run has been completed).

So this example should check for the presence of the helper app, install it as necessary - and then, after popping up a couple of initial dialogs (the second of which is critical), go on to execute the rest of the script. To help compare differences in appearance, dialogs are used for the install routine, and an alert for the main body of the script. (I've also inserted some comments within the code, in the hope that they'll make for slightly easier reading):

-----------------

property app_name : "Alert"

on rest_of_script()

(* define the title and text for the next message *)
set title_text to "Apples and Oranges"
set message_text to "\"After a week with a Windows machine I get the feeling " & ¬
"that this system is designed by people who know a lot about computers. " & ¬
"Macs, on the other hand, seem to be designed by people who know a lot " & ¬
"about people.\"" & return & "- Nigel Kendall, The Times (UK)"

(* make sure any previous dialog is dismissed *)
tell application "System Events" to tell process app_name to if exists window 1 then
set frontmost to true
keystroke return
repeat while exists window 1
delay 0.4
end repeat
end if

(* send the message to the target app *)
ignoring application responses
tell application app_name to show_alert(title_text, message_text, 30)
end ignoring

(* wait for the resulting dialog to appear - and move it to required position *)
tell application "System Events" to tell window 1 of process app_name
repeat until exists
delay 0.1
end repeat
set position to {4, 26}
end tell

end rest_of_script


to install_app(file_path)

(* check whether Script Editor is running... *)
tell application "System Events" to set quit_SE to not (exists process "Script Editor")

(* ...and then launch it, regardless *)
launch application "Script Editor"

(* define the script to be saved *)
set script_text to "to show_alert(title_text, message_text, view_time)" & return & ¬
"activate" & return & "display alert title_text message message_text giving " & ¬
"up after view_time" & return & "if view_time is 0 or view_time > 60 then " & ¬
"return quit" & return & "tell application \"System Events\" to set process " & ¬
"\"Alert\"'s visible to false" & return & "end show_alert" & return

(* write the script to a new Script Editor document, save it - and close its window *)
tell application "Script Editor"
tell (make new document with properties {contents:script_text}) to ¬
save as "application" in file_path with stay open
close window 1 saving no
end tell

(* quit Script Editor - but only if it wasn't running previously *)
if quit_SE then tell application "Script Editor" to quit

end install_app


to start_script()

(* define the target file path for the applet [insert 'from user domain', if preferred] *)
set file_path to (path to applications folder as Unicode text) & app_name & ".app"

try

(* check for the existence of the application file *)
file_path as alias

(* if it already exists, then continue with rest of script *)
rest_of_script()

on error number -43 (* file not found, so it needs to be created *)

(* let the user know that we need to do an install *)
display dialog "This script requires the installation of a small helper application " & ¬
"for certain alert messages. (Script Editor will be used to help with the " & ¬
"installation.)" & return & return & "Install the application \"" & app_name & "\" now?"

(* user seems to have agreed, so call the installing subroutine *)
install_app(file_path)

(* confirm that installation is complete - and invite user to continue with rest of script *)
display dialog "The application \"" & app_name & "\" has been installed in " & ¬
"your Applications folder. " & return & return & "You can now either " & ¬
"click OK, and continue with the script - or Cancel, to run it later."

(* the above dialog also offers a useful hiatus, actually making it safer for the script to continue... *)
rest_of_script()

end try
end start_script


start_script()

-----------------

Rather less than perfect, perhaps - but hopefully acceptable enough for a vanilla effort.

Um... looking back over what I've just tapped in, I seem to have gone on a bit longer than I'd intended. Sorry, folks... :-)

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Is there a way to keep a floating window open?
      • From: "David B. Gustavson" <email@hidden>
References: 
 >Re: How do you get a stay-open applet to quit? (From: has <email@hidden>)
 >Is there a way to keep a floating window open? (From: "David B. Gustavson" <email@hidden>)
 >Re: Is there a way to keep a floating window open? (From: kai <email@hidden>)
 >Re: Is there a way to keep a floating window open? (From: "David B. Gustavson" <email@hidden>)

  • Prev by Date: Re: Making Folders
  • Next by Date: Re: Making Folders
  • Previous by thread: Re: Is there a way to keep a floating window open?
  • Next by thread: Re: Is there a way to keep a floating window open?
  • Index(es):
    • Date
    • Thread