simple question, with (hopefully) a simple answer

Everything is moving along nicely thanks to the excellent help received on this forum.

But, I have slight problem in my script. I am sure there is a simple answer and I’m almost embarrassed at having to ask and annoyed I’ve not managed to work it out myself.

OK, here goes:

In my script, the user is asked to enter a name. If the name already exists in a predefined list a dialog box comes up and tells them to try again and then it goes back to the enter name dialog box.

However, the dialog box box that warns them the name already exists switches the whole program to Finder and, instead or returning back to script editor (or the applescript if I save it as an application) it just stays at Finder and the icon for script editor/applescript application starts jumping in my dock and I have to go back manually.

Completely stumped and beginning to think the otherwise excellent “Applescript for Dummies” is pitched at an intelligence even higher than my own. :wink:

Hi,

it’s hard to give the right answer without having the code :wink: , I try it anyway:

¢ If there is a Finder tell block with a activate command just before the warning dialog box,
try to remove “activate”, maybe it’s not necessary to bring the Finder frontmost
¢ or try “tell me to activate” before the display dialog line

Ah, thanks. Figured out the problem. I’d put in the tell application “Finder” too early:

set which_client to choose from list choose_client with prompt “Choose client?” default items {“…add item”}
if “…add item” is in which_client then
repeat until which_client does not contain “…add item”
set new_client to text returned of (display dialog “New client?” default answer “” buttons {“Cancel”, “Add”} default button 2)
tell application “Finder”
if new_client is in edited_list then
display dialog “Client already exists. Please try again” buttons {“OK”} default button 1
else
set new_folder to make new folder at desktop with properties {name:new_client}
set which_client to new_client
end if
end tell
end repeat
end if

There are variables mentioned here that are defined in other parts of my script so it may not seem like it would work.

So moving the tell application: “Finder” as follows solved it.

set which_client to choose from list choose_client with prompt “Choose client?” default items {“…add item”}
if “…add item” is in which_client then
repeat until which_client does not contain “…add item”
set new_client to text returned of (display dialog “New client?” default answer “” buttons {“Cancel”, “Add”} default button 2)
if new_client is in edited_list then
display dialog “Client already exists. Please try again” buttons {“OK”} default button 1
else
tell application “Finder”
set new_folder to make new folder at desktop with properties {name:new_client}
end tell
set which_client to new_client
end if
end repeat
end if

Hi, Jonty.

As Stefan hints, dialogs are displayed by the applications in whose tell blocks the commands appear. If the commands aren’t in tell blocks, they’re displayed by the application running the script. You can activate a specific application to bring it to the front in order to display a dialog, but it’s often tidier to tell whatever application happens to be frontmost at the time to do the displaying:

tell application (path to frontmost application as Unicode text)
	display dialog "Blah blah blah"
end tell

It’s quite a bit more to type, of course, but if you need to use ‘display dialog’ at several points in a script, you could put the above (or some variant of it) into a handler.