Bringing a text input dialog to front

I’ve written a script to ask the user what they want to do when a DVD is inserted. It works fine except I can’t find how to bring the dialog window to the front without having to manualy select it.

Is there a command to do this? Any help woud be greatly appriciated. :wink:

Here is the script…

--set the folder locations for DVD video_ts folders
set originalDVD to "folder:location:"
set compressedDVD to "folder:location:"

--asks user what they want to do with the inserted DVD
set tempVar to display dialog "        What do you want to do with this DVD?" buttons {"Watch It", "Save It"} default button 2

set toDo to button returned of tempVar

--actions to run if user wants to save the DVD
if toDo is equal to "Save It" then
	
	--asks user to enter the name of the video_ts folder to be created for the backed up and compressed DVD files	
	set tempVar to display dialog "          Please enter the name of the DVD." default answer "DVD_NAME" buttons {"OK"} default button 1
	
	set dvdName to text returned of tempVar
	
	--creates two folders for the video_ts files	
	tell application "Finder"
		make new folder at originalDVD with properties {name:dvdName}
		make new folder at compressedDVD with properties {name:dvdName}
	end tell
	
	--launches the application DVD Player to verify the DVD before saving it	
	launch application "DVD Player"
	activate application "DVD Player"
	tell application "DVD Player"
		play dvd
		delay 5
		stop dvd
	end tell
	
	quit application "DVD Player"
	
	--launches the application DVDBackup
	launch application "DVDBackup"
	activate application "DVDBackup"
	
	
	--actions to run if user wants to watch the DVD	
else if toDo is equal to "Watch It" then
	
	launch application "DVD Player"
	activate application "DVD Player"
	tell application "DVD Player"
		play dvd
	end tell
	
end if

Hi,

This usually happens when I’m running a script app from another script. Use the ‘activate’ command before the dialog. For instance,

activate
display dialog “hi”

gl,

Another way, which can save some activation activity if you don’t particularly want it, is to the tell the application that’s already frontmost to do the displaying:

tell application (path to frontmost application as string)
  display dialog "Hello"
end tell

That worked perfectly, thanks!

I had tried activating the script like I did for the applications but that didn’t work. I didn’t realize that all I had to do was run the activate command by itself.

Hi creoguy,

You’re welcome.

Any command has a target. When a valid command is not in a tell block then the target is the script app.

BTW, if you tried Nigel’s suggestion, and you get the beachball, then press Command + “.” to cause an error. That method will work depending on the app that launches the script app (eg. Script Editor).

gl,

Thanks for the heads-up on that, Kel. I’ve never ever, in the past seven years, had any problem at all using the frontmost application to display a dialog. But testing it with various apps now, I find I do have one or two non-Apple, non-scriptable ones that won’t cooperate. One of them doesn’t even respond to ‘activate’!

Here is my finished script for saving DVD’s. I discovered a few other things that I wanted to add to make the script a little more user friendly.

Again, thanks to everyone who gave me help when I ran into trouble. :smiley:

--set the folder locations for DVD video_ts folders 
set originalDVD to "folder:location:"
set compressedDVD to "folder:location:"


--the folowing actions find a local disk that contains a VIDEO_TS folder
set all_disks to list disks

set disk_count to count all_disks

repeat with i from 1 to disk_count by 1
	
	set file_list to list folder item i of (list disks) & ":"
	
	if file_list contains "VIDEO_TS" then
		set disk_number to i
		set dvd_name to item disk_number of all_disks
		
		activate
		--asks user what they want to do with the inserted DVD
		set temp to display dialog "What do you want to do with this DVD?" default answer dvd_name buttons {"Watch It", "Save It"} default button 2
		
		set new_dvd_name to text returned of temp
		set to_do to button returned of temp
		
		--actions to run if user wants to save the DVD
		if to_do is equal to "Save It" then
			
			tell application "Finder"
				
				--creates two folders for the video_ts files if the DVD is more then 4.7 GB or one if less then or equal to 4.69
				set total_size to the physical size of disk dvd_name
				set dvd_size to total_size / 1.0E+9
				
				if dvd_size ? 4.69 then
					make new folder at compressed_DVD with properties {name:new_dvd_name}
					
				else
					make new folder at original_DVD with properties {name:new_dvd_name}
					make new folder at compressed_DVD with properties {name:new_dvd_name}
				end if
			end tell
			
			--launches the application DVD Player to verify the DVD before saving it
			launch application "DVD Player"
			activate application "DVD Player"
			tell application "DVD Player"
				play dvd
				delay 5
				stop dvd
			end tell
			
			quit application "DVD Player"
			
			--launches the application DVDBackup
			launch application "DVDBackup"
			activate application "DVDBackup"
			
			exit repeat
			
			--actions to run if user wants to watch the DVD	
		else if to_do is equal to "Watch It" then
			launch application "DVD Player"
			activate application "DVD Player"
			tell application "DVD Player"
				play dvd
			end tell
			
		end if
		
	end if
	
end repeat