"Choose file" with a filename selected in list?

Hello,

I’m trying to write a script that includes “choose file” with a default location, and a filename already highlighted in the list of files.

I know that “choose file name” will display a dialog with a name already selected, but I want to display a full list of of files in a folder, with one filename already selected from the list that shows other files in the same folder.

Is this possible?

Thanks for any help.

No, not with the choose file command,
you can work around it creating a list of file names and use choose from list

Thank you, Stefan!!

The default location parameter can pre-select a folder

choose file default location alias "Macintosh HD:Users:merickson:Desktop:Crew Shows"

I don’t know how to make a default selection of one file from that folder.

It’s a work around, so you need to create a list that you can choose the file name from.

tell application "Finder"
	set x to choose folder
	set y to every file in x as alias list
	set z to {}
	repeat with eachfile in y
		set end of z to name of eachfile
	end repeat
	set zz to choose from list z
end tell

From there, you’ll need to write code to find the appropriate file and do what you want with it.

You don’t even need to bother the Finder :smiley:


set folderpath to path to desktop
tell application "System Events"
	set filenames to name of every file in folderpath whose name does not start with "."
end tell
if filenames is {} then
	return
end if
set usrchoice to choose from list filenames
if usrchoice is not false then
	set chosenfilename to item 1 of usrchoice
	set filepath to ((folderpath as text) & chosenfilename)
	-- more code...
end if

Script tested on Mac OS X 10.5.5.