How to hide extension in "choose from list" file list

Hi,
I’m trying to display all files that have the extension “.conf” but I don’t want the extension to show. How do I do that? I found some generic solution but thought maybe there is a faster way when you know the file extension…

And how do I exit the script when no file got chosen?

set dosbox to "/Applications/DOSBox.app/Contents/MacOS/dosbox"
set sierraFolder to (path to application support from user domain as text) & "sierrahelp:"
set sierraFolderPOSIX to POSIX path of sierraFolder
set the_list to ""
set nl to ASCII character 10
tell application "Finder"
	set file_list to name of every file of folder sierraFolder whose name ends with ".conf"
	repeat with entry in file_list
		set the_list to the_list & nl & entry
	end repeat
end tell
set options to (((choose from list file_list with prompt "Which Sierra game do you want to play?") as string) & "\"" & "&> ~/.local/logs/dosbox0.74.log &")
if options is not false then
	do shell script dosbox & " -conf \"" & sierraFolderPOSIX & options
else if options is false then
	-->how do I abort?
end if

“Name”, in Finder always is with extension. To easily get a list of extension-less names the extensions should be hidden in the first place.
To hide them en block:

tell application "Finder"
	set file_list to every file of folder sierraFolder whose name extension is ".conf"
	repeat with entry in file_list
		set extension hidden of entry to true
	end repeat
end tell

You can, of course, split off the extension from the name using text item delimiters when you want to keep extensions visible in Finder:

set aName to "somefile.txt"
set text item delimiters to "."
set aName to 1st text item of aName
set text item delimiters to ""
aName --> "somefile"

With extensions hidden, replace the Finder tell block in your script:

tell application "Finder" to set file_list to displayed name of every file of folder sierraFolder whose name extension is ".conf"

(Script does not use ‘the_list’ which gets built in the repeat loop).

To abort:

if options is not false then
   do shell script dosbox & " -conf \"" & sierraFolderPOSIX & options
end if

Script will end by itself when options is anything else but false.

set dosbox to "/Applications/DOSBox.app/Contents/MacOS/dosbox"
set sierraFolder to POSIX path of ((path to application support from user domain as text) & "sierrahelp:" as string)
set AppleScript's text item delimiters to return
set fileNames to every text item of (do shell script "ls " & sierraFolder & " | grep '.conf$' | rev | cut -d . -f2- | rev")
set AppleScript's text item delimiters to ""
set options to choose from list fileNames
if options is false then
	return
end if
	
set option to item 1 of options

do shell script quoted form of dosbox & " -conf " & quoted form of (sierraFolder & option) & " &> ~/.local/logs/dosbox0.74.log &"

Thanks alastor933 and DJ Bazzie Wazzie, but I have problems with both your solutions.

DJ Bazzie Wazzie: your script gives me the error “List is empty.” number -50
(I got at least one file with the extension conf in there)

alastor993: do you mean the script should look like

set dosbox to "/Applications/DOSBox.app/Contents/MacOS/dosbox"
set sierraFolder to (path to application support from user domain as text) & "sierrahelp:"
set sierraFolderPOSIX to POSIX path of sierraFolder
set the_list to ""
set nl to ASCII character 10
tell application "Finder"
	set file_list to every file of folder sierraFolder whose name extension is ".conf"
	repeat with entry in file_list
		set extension hidden of entry to true
	end repeat
end tell
tell application "Finder" to set file_list to displayed name of every file of folder sierraFolder whose name extension is ".conf"
repeat with entry in file_list
	set the_list to the_list & nl & entry
end repeat

set options to ((choose from list file_list with prompt "Which Sierra game do you want to play?") as string)
if options is not false then
	do shell script dosbox & " -conf \"" & sierraFolderPOSIX & options & "\"" & "&> ~/.local/logs/dosbox0.74.log &"
end if

With this I get the error “Finder got an error: Can’t get displayed name of every file of folder "MacOSX:Users:Dominus:Library:Application Support:sierrahelp:" whose name extension = ".conf".” number -1728 from displayed name of every file of folder “MacOSX:Users:Dominus:Library:Application Support:sierrahelp:” whose name extension = “.conf”

As for the abort on cancel, the script then executes dosbox anyway, most likely because options do get set to something…

Then you have mislead me with the wrong extension. The extension is case sensitive and to make it case insensitive use option -i with grep so every file that ends with .conf or .CONF will all work. I’ve tested it and use this method myself for years and don’t have any problems at all.

thanks, got it now. the posix path needed to be in quoted form, since application support folder has a space :slight_smile:
I wanted to post you a screenshot that the extension was correct and then had to use quotes and I realized :slight_smile:

Sorry my fault too… I use it normally with quoted form too, I always use quoted form normally with posix path. I tested it on my desktop and there is no spaces in that path so that’s why it worked on my desktop normally.

Nice that it works now

A typo, sorry:

tell application "Finder" to set file_list to displayed name of every file of folder sierraFolder whose name extension is "conf"

There should not be a dot on the extension.

As regards the modified script you posted; I said to replace the Finder tell block - that’s not what you did.

I misunderstood what you meant by ‘abort’ - it was ‘cancel dialog’, not ‘end script’. DJ’s solution does what you meant…