Problem selecting files with command 'choose file'.

Hi there,

I’m new to the world of Mac and scripting, but loving it so far!! :slight_smile:

I build a script where I want to select a file from the folder ‘Downloads’ where only the files with the extension .csv are selectable and the rest is grayed out. I think it has to work via chosing the right type in te commandline from the ‘choose file’ command. I tried to find which constant I should use but I’m lost. There are many predefined systemconstants starting with public.??? but I can’t find .csv. Trying to find out I got lost in the help via te script language guide in defining Uniform Type Identifiers. Is there no easier way to do this? If not is there a simpler way to prefilter selectable files?

Greetings,
Paul

It’s addictive, be careful! :stuck_out_tongue:

You can do this by File Type, like "PDF " (and yes, there’s a space at the end of that) or by the UTI. The Kind does not appear to work, at least on Tiger.

Here’s a little quickie if you don’t know the File Type. Open Applications>Utilities>Terminal and type: mdls then a space and drop your .CSV file into it and press Return. Copy the kMDITemContentType from the window and paste it into your script. (I would put it in a list even if it’s one item so I could add more later without forgetting to make it a list. A list of one item is still a list.) Note: File Type and Creator Type are sometimes listed in the results but since Apple seems less inclined to require this, it’s less prevalent than it was (and less than it should be - they’re still incredibly useful :frowning: ).

here’s a simple example:

choose file of type {"com.adobe.illustrator.ai-image"} default location (path to desktop) without invisibles

Hope that helps.

Have fun,
Jim Neumann
BLUEFROG

The operating system doesn’t install the “public.csv” UTI so we need a tool to install it.

I gave the soluce in the thread entitled:
“Select file using type for file extesion” (the typo is in the original title :wink:

http://macscripter.net/viewtopic.php?id=28424

Yvan KOENIG (from FRANCE lundi 23 février 2009 15:40:16)

Hi,

if the folder location is constant, I suggest this


-- assuming theFolder is an alias
tell application "Finder" to set csvFiles to name of files of theFolder whose name extension is "csv"
set theFile to choose from list csvFiles
if theFile is false then return
set theFile to alias ((theFolder as text) & item 1 of theFile)
--> result is the alias of the chosen file

Stefan:

Since this is a more unusual case, where the UTI is apparently always dynamically mapped by default, I agree with you. But as a general rule, I try and avoid using name extension as my first criteria since this can easily be spoofed. (This is one of those Windows-like behaviors I wish Apple had never implemented.).

I have a JPEG file which has no File Type or Creator Type (not unusual these days). It reports properly and LaunchServices behaves as expected. Now if I change the extension to .RTFD the icon changes, mdls reports it as an RTFD file as does the Finder i[/i], and LaunchServices decides that TextEdit should open it for me!

Just a thought. ahh, for the simpler days of File Types and Creator Codes and the extensionless magic of the Mac! :smiley:

Jim

If you apply what I described in the given link, the 'public.csv" UTI will be available in the system’s database and you will be able to use

choose file of type {public.csv"}

I filed this bug report:

Your tracking number for this issue is Bug ID# 6612880.

[i]Hello

As Numbers is able to import csv files, it would be useful to change it’s plist so it install the “public.csv” UTI in the system’s database.

At this time we can’t use the standard additions’s Choose File with the UTI “public.csv”.

For my own use, I created a small application which installs the UTI but I think that it’s the Numbers duty or the operating system’s one.

In Numbers, it just requires to add:[/i]

UTImportedTypeDeclarations


UTTypeConformsTo

public.composite-content
public.data

UTTypeDescription
CSV family
UTTypeIconName
Document.icns
UTTypeIdentifier
public.csv
UTTypeTagSpecification

com.apple.macos.ostype
CSV
public.filename-extension

csv



[i]in the info.plist file.

But it would be fine to do the trick in the operating system itself.

Adding that in the next Security Update would be really fine (will apply to macOS 10.4 and macOS 10.5)[/i]

Yvan KOENIG (from FRANCE lundi 23 février 2009 17:31:11)

Nicely done, Yvan! :smiley: Hope that one gets some attention.

Cheers,
Jim

SUPER!!!
I used the code from Yvan Koenig in plist and followed the instructions and tada!! It’s working.:smiley:
Thank you very much :slight_smile:

Regards,
Paul Biester

Thanks for the feedback.

I will add some words to my report.

I will tell them that Bentoy, a toy distributed by FileMaker (a 100% Apple subsidiary) is also using csv files.

Yvan KOENIG (from FRANCE mardi 24 février 2009 12:20:23)