Only show certain file types in choose file window

Hey guys,

I know I can have a choose file window only allow selection of certain file types like this

set excelFile to choose file with prompt ¬
			"Choose Excel file to append data to" default location (path to documents folder) of type {"org.openxmlformats.spreadsheetml.sheet", "com.microsoft.excel.xls"} without invisibles

of like this (although this way is spotty)

set excelFile to choose file with prompt ¬
			"Choose Excel file to append data to" default location (path to documents folder) of type {".xlsx",".xls"} without invisibles

but this will still show you all of the nonselectable files, so if you’re looking through a folder of many items, you still have to find the right file.

Is there a way to have ONLY the specified file types appear in the choose file window?

Thanks,

Tim

No

how negative…

I use this

set inputfile to POSIX path of (choose file of type {"csv", false})

but this does not hide the non-selectable items

As StefanK already wrote, the answer is no.
You may file a request for such enhancement to Apple.
I’m not sure that they have plans to enhance a scripting addition but if you don’t ask you may be sure that you will not get what you want.

You may also look at Smile.
I know that they have their own tools to choose files, maybe they offer what you want.

Yvan KOENIG (VALLAURIS, France) samedi 5 juillet 2014 20:38:38

Hey There,

As has been noted you cannot do this with choose file, but you can roll-your-own.


-------------------------------------------------------------------------------------------
set fileNameList to {}
set _location to (path to home folder as text) & "test_directory:"

tell application "System Events"
	set quit delay to 0
	set fileNameList to fileNameList & (name of files of folder _location whose type identifier is "com.barebones.bbedit.shell-worksheet")
	set fileNameList to fileNameList & (name of files of folder _location whose type identifier is "com.microsoft.excel.openxmlformats.spreadsheetml.sheet")
end tell

if length of fileNameList > 0 then
	set chosenFileList to choose from list fileNameList with prompt "Pick One or More Files:" with multiple selections allowed
	if chosenFileList is not false then
		repeat with i in chosenFileList
			set contents of i to (_location & (contents of i)) as alias
		end repeat
		tell application "Finder"
			open chosenFileList
		end tell
	end if
end if
-------------------------------------------------------------------------------------------

As long as your file extensions are consistent you can probably find files using the shell faster than with System Events, although there are potential pitfalls to doing so when a directory contains packages like .app “files”.


set _location to quoted form of (POSIX path of ((path to home folder as text) & "test_directory:"))
set fileNameList to paragraphs of (do shell script " cd " & _location & "; ls *.xlsx *.worksheet")

You could add an item to the list which when selected permits changing the _location path directly via display dialog or via choose folder.

You don’t get the niceties of the choose file dialog, but it works.

I wouldn’t hold your breath. What the OP is asking for can’t be done by any app (without considerable hacking) for the simple reason that it would violate Apple’s interface guidelines. He may think it’s clever to show only the relevant files, but as the only app doing so, he might also scare his users half to death when they can no longer see any other files.