"Display dialog" and applecript running in the back?

Is their a way to display a dialog that only show info, whill applescript is stil is doing its job whitout waiting for someone to press a button?

Imac G5, Mac OS X (10.4.3)

Posted on Jan 3, 2006 6:39 AM

Reply
11 replies

Jan 3, 2006 3:15 PM in response to Egeberg

Egeberg,
No, not with Script Editor. It does one thing at a time, and if that thing is displaying a dialog then it waits to finish before moving on. You can set a dialog to gracefully timeout and have the script continue processing instead of hanging.

display dialog "This is a time out." buttons {"cancel"} default button 1 giving up after 5

Or take a look at XCode.

Reese

Jan 3, 2006 6:08 PM in response to Egeberg

Hi Egeberg,

Is their a way to display a dialog that only show
info, whill applescript is stil is doing its job
whitout waiting for someone to press a button?


Yes, but it is not something really simple to accomplish. If you let us know exactly what you are attempting to do and what kind of info you need displayed while your script is running we might be able to help you come up with a solution for your problem a little easier. Sometimes this really isn't that easy to accomplish with AppleScript Studio either. It all just depends on exactly what information you are wanting to display, how you want it to be displayed and your skill level in scripting.

Hope to be able to help more soon...

iBook G4 1GHz Mac OS X (10.4.3) 640 MB RAM

Jan 4, 2006 12:35 AM in response to Chachi

Hi Chachi!

Thanks!
I have made a little script that counts how many unread message I have in my mail.app, as a rule, each time I receive a new message
And its working fine, but the problem is when I use ”display dialog” the script wait for the default button to be press.(it wait fore action), and Mail.app also wait, for the script to end its job.
So what I want is to display info, for receiving a mail, end of job and the info only close if I close it, if it gets more mails, mail.aps start the script again and display the new info In the old info box, instead of waiting fore some action!

Jan 4, 2006 6:30 AM in response to Egeberg

Hi Egeberg

Without any addition to AppleScript you can use the "giving up after" parameter of the Display Dialog command:

display dialog "Hello" buttons {"Cancel","OK"} default button "OK" giving up after 2 with icon note
if button returned of the result is "" and gave up of the result is true then
-- do whatever the default button would have done
end if

2 is a time in seconds which you can modify as you like.

Hope this helps.

H

Message was edited by: HD I posted this before fully reading reese's post but hopefully it expands on it rather than just duplicating it.

H

Jan 4, 2006 7:58 AM in response to Egeberg

Ah, sorry, got you now.

You could script any application that can display a text window. For example, with Tex-Edit Plus , you can open a window and update its contents from time to time.

-- begin pseudo-code:

tell application "mail"
set message_count to count new messages
end tell
set message_message to "You have "& message_count " new messages."
tell application "Tex-Edit Plus"
activate
if not exists window "New messages" then
make new window at front with properties {name: "New messages"}
end if
tell window "New messages"
set index to 1 -- bring to front
set contents to "" -- clear existing content
set contents to message_message --update
end tell
-- carry on doing other things
--end pseudo-code

Or you could use the third-party free AppleScript environment Smile to keep an open dialog or message window. (There's quite a learning curve but the benefits are enormous.)

Hope this helps.

H

Jan 5, 2006 3:14 PM in response to Egeberg

Hi Egeberg,

If you want to avoid reinventing the wheel there is already a really slick freeware add-on to the Mail application that will do what you describe and quite a bit more. I use it all the time. If you're interested, its name is " Mail.appetizer" and it's well worth having a look at.

I also understand that it can be fun to create your own "toys" that do what you want them to do 😉

To display a dialog and allow your script to proceed with what it's doing you need to "offload" your display dialog statement to another application. The best way to accomplish this is to create an empty, "stay open" application that can work as a "slave" app for you that you can call on when you need it. If you save your script as a " script bundle" you can store this empty application within your script and call on it using path to resource NameOfYourHelperApp.

I can post an example of how this would work if you'd like. Like I mentioned before though, you really need to be quite capable in scripting in order to properly write and debug a script like this. I really don't know what your skill level is and, because of this, hesitate to post an example due to the amount of description I would find necessary to teach someone all the steps necessary. Just let me know if you feel confident enough in your skills and I can definitely try posting an example script. I have a script that will, as far as I can tell by your description thus far, do exactly what you are asking. Also, if you could post the script you are currently using, I could incorporate it into the example for you.

I reiterate my thoughts on using "Mail.appetizer" though. I should note that I have absolutely no affiliation with the creators of this application. I just love it and use it ALL the time.

Jan 5, 2006 3:53 PM in response to Egeberg

You can use SEC Helper, it a part of Salling Clicker.
If you don't use the BlueTooth part, it's free. I use it to do just what you want to do.
It displays the message like Address Book's 'Large Type' across the screen, very unintrusive.

If you are interested, I have a script to do just that. And it doesn't even fire up Mail, I use SOAP call to a service to fetch message count from my POP server.

Jan 6, 2006 12:39 AM in response to Cyclosaurus

That is really, really cool, Cyclo. I'd passed on Salling a while back as I'm somewhat anti-cell-phone. Wow was I missing a lot of really neat commands in their FBA!

Here is my attempt at a more vanilla solution for popping "orphaned" dialogs. I use Dock.app to spawn the dialog because activating the dock brings no windows to the fore, and the dock (dashboard, expose, etc.) continue to function normally while the dialog is displayed.

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "Mail" to my display_dialog((unread count of inbox as string) & space & "unread messages.")


on display_dialog(x)
tell application "Dock" to activate
tell application "System Events" to keystroke return -- attempt to close extant dialogs
tell application "SystemUIServer" to activate -- if there was no dialog, another app must outlet the keystroke before we spawn a new dialog
do shell script "osascript -e 'tell application \"Dock\" to display dialog \"" & x & "\"' &> /dev/null &"
end display_dialog</pre>
The generic keystroke return was necessary because I could find no other way to reliably test for previously opened dialogs in Dock.app. I then had to put in the SystemUIServer line because, in the absence of an old dialog, Dock.app was closing the new dialog as fast as it spawned! The dialog command itself is encapsulated in a shell script so that the main script can quit immediately without waiting for a result. This was more reliable for me than an ignoring application responses block, but your results may vary.

PowerMac G5 (June 2004) 2x1.8GHz 1.25GB, PowerBook G4 (12-inch DVI) 1x1GHz 768MB Mac OS X (10.4.3)

Jan 6, 2006 12:53 AM in response to Chachi

Hi Chanchi!

"mail.appetizer" is what I need ;O)
thanks

I just thought there was some other easy routine for example ”msgbox” or some thing similar, I didn’t know about.
In my young days I where programming in “Basic” “Pascal” , and it was easy.
But I don’t have the time now to start to learn a new “language”,.
So "mail.appetizer" is perfekt, greate again

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

"Display dialog" and applecript running in the back?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.