need to have a "working" or "please wait" window

I’m working on a script that includes in it the process of mounting a network drive.

tell application "Finder"
	mount volume "smb://" & username & ":" & userpassword & "@serveraddress/" & username
end tell

If the computer’s network connection is good, this typically works great and is finished within a couple of seconds. If there’s a problem, however, it takes a very long time for the beach ball to go away and my “on error” message to finally appear.

How can I at least create a “Please wait…” window?

Even better would be a way (by using “ignoring” or something like that) to make this time-consuming unsuccessful process take place in the background so that the user can at least continue to open other applications or that sort of thing.

Thanks for any help and ideas.

AppleScript: 2.1.1
Operating System: Mac OS X (10.6)

add this code to your script to display that please wait window…

display dialog "Please Wait..."


Problem with that is no script can run underneath it, I don’t know if run script might help, I’ll see.

Well, after the lengthy process of not succeeding, my “on error” task runs, which is a dialog. So i could place the “Please wait…” dialog before the task begins, but by default an “ok” and a “cancel” button are placed on the dialog, so the script wouldn’t move on to attempting the connection until the user responds to the “please wait” dialog.

Unless you know of a way to have the “Please wait…” stay up during the mounting, and go away when the mounting fails or completes. That’s really what i’m looking for, sorry i wasn’t more specific.

AppleScript: 2.1.1
Browser: Firefox 3.5.5
Operating System: Mac OS X (10.6)

No, you can’t do it that way I was thinking. And like I said you can’t run script under a dialog, it will just pause the script until dismissed.

However this is fairly possible in ASOC :confused: I think.

Thanks for looking into that. Too bad.

Interesting idea. I, unfortunately, have no experience at all with that. Can the Obj. C be included within a “normal” applescript, or does it require a different editor or something?

Another thought: Does anyone know of a way to stop the mounting part of the script after a certain amount of time? Say, 10 seconds?

Having the dialog as a window in ASOC is very doable.

Or you could simply have the dialog time out after a certain number of seconds:

display dialog "Please wait..." giving up after 2

And if you know about how many seconds it will take, it can even play a sound when it’s done:

delay 30
do shell script "afplay '/System/Library/Sounds/Glass.aiff'"

You can do this using "Cocoadialog.

The example “” which as its name implies uses a progress bar seems to respond to your request. # progressbar3

You embed the shell script in an AppleScript like this:

-- my test with an USB drive
set myDevice to "CYAN CC"
set myOption to "mount" --unmount
set username to ""
set userpassword to ""

	do shell script "
rm -f /tmp/hpipe
mkfifo /tmp/hpipe

/Applications/ progressbar \\
	--indeterminate --title \"Mounting disk.\" \\
	--width 250 --height 80 \\
	--text \"Please wait...\" < /tmp/hpipe &

exec 3<> /tmp/hpipe
echo -n . >&3

# do all of your work here
# like this
# diskutil " & myOption & " $(diskutil list | awk '/" & myDevice & "/{print $NF}')

# or like this
osascript <<-EOF
tell application \"Finder\"
	say \"CPU speed is \" & (system info)'s CPU speed
	delay 2
	beep 2
end tell

exec 3>&-
rm -f /tmp/hpipe
exit  0"
on error err number errNum
	display dialog err & return & "error #" & errNum with title "ERROR" buttons "OK" default button 1 with icon 0
end try

The only regret I have on the progress bar is that it has no “- float” option as in other “CocoaDialog” dialogs.

Interesting idea. Though i’m not thrilled about the temp file that creates, i’ve tried it out. I might be missing something, though, because i can’t get it to work, and i have downloaded and found a place for

My understanding is that since this is shell script, that further shell script is all that you can do in the “do all of your work here” section. Is there a way to do non-shell work in that place? I’ve tried a few weak ideas with no success.

I would just get Xcode, copy and paste your code, create your own little dialog which won’t stop processes, not too hard. Unless Cocoa Dialog does it perfectly.

Yeah. I have Xcode but haven’t used it yet. It seems it’s time to, so i’ve been simultaneously learning how to properly use that (and ASOC) while also trying clem’s idea.

Place your script inside the finish launching handler, create a window in Interface Builder which will be your dialog, then connect a window property and use makeKeyAndOrderFront_(sender) to open and performClose_(sender) to close, you can even add progress indicators if you like, which take more work, you can find out how to do properties and linking in unscripted and craig’s new tutorial on the ASOC forum.