macOS: Read file Meta Data

11 days ago I get that idea (from where ?) and was lucky enough to be able to get the “How To” (get the file Meta Data for macOS).

Also, it was my first compile and it worked even if I forgot to pass the parameters (so no parameter returns the whole lot of Meda Data).

I also forgot to fill the PopupMenu and I was not able to really found the code for enabling this for Linux and WIndows.

In the mean time, you can see what kind of meta data is available for your files.

Click in the “default Icon” (below the Apple logo) or drop the item (one) into the “default Icon” and you will get all Meta Data.

For all items, you will get logical size and physical sizes,
for images, you will get the number of pixels, the size in Pixels (width, height), etc.
public.text (UTI ?), etc.

and plenty other things.

BTW: I was so happy to have a good momment that I saved the project, build the application and never go back to it since.

The link to download the macOS version is here .


For sqlite, I get:
kMDItemContentType = “com.xojo.database.sqlite”
kMDItemContentTypeTree = (

Just in case you prefer the code only:

You can put that code in Window1.DropEvent (for example) or remove the ObJ.FolderItemAvailable line and replace it with an OpenDialog part.

[code] // Deal with the dropped item
Dim OpenFI As FolderItem
Dim s As New Shell
Dim cmd As String

If Obj.FolderItemAvailable Then
// Use a local variable
OpenFI = Obj.FolderItem

#If TargetMacOS Then
  cmd = "mdls " + OpenFI.ShellPath
  If s.ErrorCode=0 Then
    TA_Result.Text = s.Result
    TA_Result.Text = "Error " + Str(s.ErrorCode)
  End If

End If[/code]

Do not forget to add a TextArea you will name TA_Result.

man mdls (in the Terminal) is your friend to get help for this command.

Unfortunately, I do not found the command (a command to get the same kind of metadata) for Linux nor WIndows.

If you only want to get the number of pixels of an image and its width,height, replace the cmd line above with:

cmd = "mdls " + "-name kMDItemPixelCount -name kMDItemPixelWidth -name kMDItemPixelHeight " + OpenFI.ShellPath

and you will get:

kMDItemPixelCount = 1157120 kMDItemPixelHeight = 565 kMDItemPixelWidth = 2048

Values are for the image I tested.

It seems that I forgot to share the application’s link :frowning: