Search code examples
applescriptacrobatfilemaker

Filemaker or applescript calculation to identify and add proper file extensions when exporting containers


I have a variety of mixed media stored in container fields that I am trying to export and open (primarily with adobe Acrobat) I am running into a problem when exporting these documents because many either do not have file extensions or when we rename them upon export and add an extension like .PDF it is often incompatible with the actual file type creating an error message from acrobat when trying to open... Is there a function, plugin or calculation that we can use on the export to properly identify the file type and add the extension on the end of the file name?


Solution

  • To set the name extension of images which not have file extension:

    You can use the unix command "file" to get the type of the image (work also on PDF's document).

    Here is an example:

    set myFolder to (path to desktop folder as text) & "Print:"
    set myfiles to list folder myFolder without invisibles
    repeat with f in myfiles
        set tFile to myFolder & f
        set na_Ext to name extension of (info for file tFile)
    
        if na_Ext is missing value then -- no name extension
            set r to do shell script "/usr/bin/file " & quoted form of POSIX path of tFile -- get the type of this image
            if "PDF document" is in r then
                set na_Ext to ".pdf"
            else if "PNG image data" is in r then
                set na_Ext to "png"
            else if "TIFF image data" is in r then
                set na_Ext to "tiff"
            else if "JPEG image data" is in r then
                set na_Ext to "jpg"
            else if "JPEG 2000 image data" is in r then
                set na_Ext to "jp2"
            else if "Adobe Photoshop Image" is in r then
                set na_Ext to "psd"
            else if "PC bitmap" is in r then
                set na_Ext to "bmp"
            else if "GIF image data" is in r then
                set na_Ext to "gif"
            else if "SGI image data" is in r then
                set na_Ext to "sgi"
            else if "Targa image data" is in r then
                set na_Ext to "tga"
            end if
    
            if na_Ext is not missing value then
                tell application "Finder" to set name extension of file tFile to na_Ext -- set the name extension of this file
            end if -- else the type of this image is not in this script
        end if
    end repeat