Display Dialog Hidden in Excel

I have a new problem that just cropped up in Snow Leopard. This script worked fine in Leopard.

The script SigCheckNum is run from other AppleScripts. The problem is that the Diplay Dialog is behind my Exel Sheet instead of on top of it. I trigger my Excel AppleScripts from QuickKeys 4. The scripts play correctly until the script SigCheckNum is run. At that point the QuickKeys icon bounces on my dock. When I click on the QuickKeys icon in the dock, the Display Dialog comes to the foreground. I can then input data, hit return and the script finishes playing correctly.

Here is an example of the script that calls the SigCheckNum script

tell application "Microsoft Excel"
	activate
	set formula r1c1 of active cell to "FIOS"
	select (get offset active cell column offset 3)
	set formula r1c1 of active cell to "FIOS Telecommunication Service”Verizon"
	select (get offset active cell column offset 1)
	run script alias "Snow Leopard Boot:DOCUMENTS:AppleScripts:SigTaxScripts:SigCheckNum.scpt"
	set formula r1c1 of active cell to "199.99"
end tell

Here is the script that seems to have the problem

display dialog "Enter Last Two Digits of Your Check Number" default answer ""
set CheckNum to "#24" & text returned of result
tell application "Microsoft Excel"
	activate
	set formula r1c1 of active cell to CheckNum
	select (get offset active cell column offset 2)
end tell

Any ideas what I’m doing wrong in Snow Leopard?

Tom Carlson

Try:


tell me
activate
display dialog "Enter Last Two Digits of Your Check Number" default answer ""
set CheckNum to "#24" & text returned of result
end tell
tell application "Microsoft Excel"
   activate
   set formula r1c1 of active cell to CheckNum
   select (get offset active cell column offset 2)
end tell

Thank you Martin. That solved it.

Is this a new function for Snow Leopard? I did not need to “Tell Me” in previous versions of the operating system.

Thanks again for the quick solution!

Tom

I have that problem, my solution is to put the display dialog inside the Excel tell block. So that Excel is putting the dialog box on top of its windows.

Thanks, Mike. That works as well.

Mike or Martin or anyone else, Is one method or the other preferable in terms of best scripting practice?

Also, I’ve noticed that when entering data into the dialog box, I type numbers and there is a delay before the actual text appears in the dialog box. Does that sound familiar? Anything that can be done from a scripting standpoint to make the text more responsive? Once again, this seems to be a new “feature” since I switched to Snow Leopard.

Thanks in advance,

Tom

I’m not sure what AppleScripting best practices are about this issue. But, by using Excels Input Box, rather than applescript’s display dialog, excel will validate that the user enters a number. Checking for two digits has do be done by the script.

tell application "Microsoft Excel"
	activate
	set CheckNum to ""
	repeat while CheckNum = ""
		set CheckNum to (input box prompt "Enter Last Two Digits of Your Check Number" type a number) as integer as text
		if CheckNum = "0" then
			-- cancel pressed
			exit repeat
		else if (length of CheckNum) ≠ 2 then
			set CheckNum to ""
		else
			set value of active cell to "#24" & CheckNum
		end if
	end repeat
end tell

I see. That makes a lot of sense, Mike.

Thanks,

Tom