How can I restrict an answer file dialog to just applications?

This lesson will show you how to filter the files shown in an answer file dialog so that it only shows applications

Show the answer file dialog

Show the answer file dialog

Create a stack with a button and a field. Name the button "Browse" and the field "Filename". Add a simple script to show the answer file dialog and handle the file path returned, to the Browse button:

on mouseUp
	## Shows a select file dialog filtered to only show applications then puts the selected filepath into field "Filename"
	answer  file "Select File:" 
	put it into field "Filename"
end mouseUp

Filter the answer file dialog

Filter the answer file dialog

The answer file script can be filtered by file type using the format "tag|extensions|filetypes". In this case, for Windows computers we use "Applications|exe|*". We can put any number of comma delimited options in the extensions and filetypes sections. Files that match any of those extensions will be shown. We could also add another line of "tag|extensions|filetypes" if we wanted the user to select from several filters using the "Files of type" option menu.

on mouseUp
	 ## Shows a select file dialog filtered to only show applications then puts the selected filepath into field "Filename"
	 ## Windows applications have the extension *.exe
	answer  file "Select Application:" with type  "Applications|exe|*" 
	put it into field "Filename"
end mouseUp

 Now the folder we opened only shows applications.

Filter by file type depending on operating system

Filter by file type depending on operating system

Different operating systems use different application file types, the operating system can retrieved using the platform function.

on mouseUp
	## Shows a select file dialog and filters to only show applications for the current operating system
	## Different OSes use different extensions for application files
	if the platform is "Win32" then
		## Windows applications have the extension *.exe
		answer  file "Select Application:" with type  "Applications|exe|*" 
	else if the platform is "MacOS" then
		## Mac OS uses APPL
		answer  file "Select Application:" with type  "Applications|app|APPL" 
	else
		## Unix based OSes don't have a particular application type
		answer  file "Select Application:"
	end if
	put it into field "Filename"
end mouseUp

 

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.