Opening AppleScript file

Mac / Xojo 2021 r3.1

Upfront I will say that I find the whole topic of FileTypes confusing.

Var fiDestination As FolderItem
fiDestination = FolderItem.ShowOpenFileDialog(FileTypeAppleScript.All)

My intent is to open a FileDialog box and offer only AppleScript files as choosable.

So I create a FileType Group which is seen below.

I am never sure what I need to specify and what I do not have to specify. In any case, I assumed that the most important thing was the Extension specification (.scpt or .scptd)

When I run the code, the dialogue box appears but I cannot actually select my test file (Garb.scpt). It is greyed out.

Screen Shot 2021-12-23 at 5.49.05 AM

Any guidance is appreciated.

I did some more testing and if I remove all the fields in the macOS Options area then my test file was selectable. So I think that I have gotten it to work.

I had filled in the Identifier and the Conforms To with stuff that I had found on the internet not knowing exactly what I was doing. That seems to have caused a problem.

What is the importance of all the fields in the macOS Options area?

Can you just ignore everything except for the Extensions field?

I understand that you need to fill in the Name field as well although I am not using it specifically.

FWIW, if you drop a file on the file types editor on macOS, it’ll populate the fields for you with the correct values.

3 Likes

Here are some explanations:

Identifier is a specific identifier for the type. If the type is unique to your app, it should start with the app identifier, followed by the type.

com.company.app-type

Conforms To is all about compatibility with other tools. For instance, our text projects “conform to” public.text. That means that they can be opened by any application which tells the system that they open files that conform to the public.text type.

Oh and I should probably mention that these are all called Uniform Type Identifiers (UTIs).

1 Like

Now the checkbox that indicates that a type is unique to your app changes where in the plist the type is generated. When checked, a type is considered Exported. If the type is owned by another vendor, like com.adobe.pdf, you would not check that box and it is considered Imported.

1 Like

If your app has no need to compatible with really old files, you can pretty much ignore the macOS Types field. That is for files that were created by apps using the old Type & Creator 4 character codes.

On the right hand side, there are three popup menus:

Type: When defining a type that is unique to your app, you can specify how the Finder treats the type. The default is File, but you can also specify Folder or Bundle. Bundle is good if you have a “file type” which is actually a folder but you want it to look like a file. Pages documents are a good example of a bundle. They’re the files where you can right-click and select “Show Contents”.

Role: Indicates the role that your app has in relation to the type, which is one of View, Edit, Execute or None. It’s a good idea to get this right as it helps the OS when suggesting apps that can interact with a file type.

Rank: Indicates whether or app shows as the Owner, a Default or an alternate app when the user right-clicks on a file and selects Open With. Owners will always appear at the top of the menu. If there’s only one “Default” defined for a type, that type will appear next. Any apps that are declared as Alternates appear below that.

These three popups define the behavior with regards to users dropping files onto your app’s icon.

1 Like

Without any definition of a file type the following code should work fine:

'load scpt file
dim theFileType as new FileType
theFileType.Name = "scpt"
theFileType.Extensions = "scpt"

dim dlg As new OpenFileDialog
dlg.Title = "Select a script file"
dlg.Filter = theFileType

dim f As FolderItem = dlg.ShowModal
if f = Nil then Return
2 Likes
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.