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.
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.
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