I do have the following problem:
I want to restrict the choose file available type to CSV only, so you can only choose a CSV file. I’ve already tried this:
set aFile to choose file with prompt “Kies om te zetten bestand:” default location alias aFolderDownload of type {“public.csv”} without invisibles
It seems that no program installs the official UTI dedicated to CSV file in the system’s database so, when we ask the properties of such a file, we don’t get 'public.csv" but something like:
type identifier:“dyn.age80g650”
A workaround was given in december 2008 by Daniel Varlet.
Save your script as an application bundle.
ctrl-click to ‘show package’s contents’
open the info.plist file and edit it to match this one:
Save the info.plist
Close the script’s window.
It may be useful to move it from a folder to an other one to force the lazy Finder to take care of the info.plist.
Run the script.
The filter will be active and will continue to be active if you save the script under an other name and execute it.
This is why I named the beast install_csv_UTI .
About 1 year ago you helped me with the attached code for selecting only *.csv files in my script. After upgrading to Snow Leopard it stopped working. Do you have a tip for me to solve this problem?
set aFile to missing value
set myPrompt to "Kies het *.CSV bestand"
repeat while aFile is missing value
set aFile to (choose file with prompt myPrompt)
tell application "Finder" to if name extension of aFile is not "csv" then
set aFile to missing value
set myPrompt to "Alleen bestanden met de CSV extensie zijn toegelaten"
end if
end repeat
get aFile
Or:
set myPrompt to "Kies het *.CSV bestand"
repeat
set aFile to (choose file with prompt myPrompt)
tell application "Finder" to if name extension of aFile is not "csv" then
set myPrompt to "Alleen bestanden met de CSV extensie zijn toegelaten"
else
exit repeat
end if
end repeat
get aFile
You can even put it in a handler:
set csvFile to chooseFileOfType("csv")
on chooseFileOfType(aFileType)
set myPrompt to "Kies het *." & aFileType & " bestand"
repeat
set aFile to (choose file with prompt myPrompt)
tell application "Finder" to if name extension of aFile is not aFileType then
set myPrompt to "Alleen bestanden met de " & aFileType & " extensie zijn toegelaten"
else
exit repeat
end if
end repeat
return aFile
end chooseFileOfType
Or using recursion:
set csvFile to chooseFileOfType("csv", false)
on chooseFileOfType(aFileType, allreadyCalledBOOL)
if allreadyCalledBOOL is false then set aFile to choose file with prompt "Kies een *." & aFileType & " bestand"
if allreadyCalledBOOL is true then set aFile to choose file with prompt "Alleen bestanden met de " & aFileType & " extensie zijn toegelaten"
tell application "Finder" to if name extension of aFile is not aFileType then tell me to chooseFileOfType(aFileType, true)
return aFile
end chooseFileOfType