Skip navigation
lanejd
Currently Being Moderated

JS - How do I Find the MIME type of a Link?

Aug 2, 2012 12:20 PM

I need to be able to find the MIME type of a linked item in InDesign. Is there a simple way to do this?

 
Replies
  • Currently Being Moderated
    Aug 2, 2012 2:09 PM   in reply to lanejd

    Yes.

     

    The number of linkable files is small enough to build a (small) database of file extension -> mime type. Then all you need to know is the file extension.

    Note that ID needs a file extension to be able to import a file in the first place, fancy file type recognition tricks Not Included.

     

    (As for the "small list" of linkable files: all you have to do is browse the Application object. There is actually a command or array of strings that contains all of them.)

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2012 3:57 PM   in reply to [Jongware]

    [Jongware] wrote:

    (As for the "small list" of linkable files: all you have to do is browse the Application object. There is actually a command or array of strings that contains all of them.)

     

    Got it -- for CS6, http://jongware.mit.edu/idcs6js/pc_Application.html#placeableFileExten sions and placeableFileTypes immediately below.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 3:21 AM   in reply to [Jongware]

    All 67 of them. Well, not all: IDRC isn't listed (maybe because it's ID internal and is really a disguised PNG).

     

    By the way, app.placeableFileTypes does and doesn't work:

     

    app.placeableFileTypes.constructor.name => Array

    app.placeableFileTypes.length => 0

     

    Looks like someone thought that placeableFileTypes would be a good idea, then changed their mind, added placeableFileExtensions, then forgot to remove placeableFileTypes. Or something like that.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 5:19 AM   in reply to Peter Kahrel

    67, eh? In my office CS4 I got 49, but that includes not-really-placeable file types such as .joboptions, lots of duplicates such as .jpg, .jpeg, and .jpe, and oddball stuff such as .AIFF and .utext.

     

    (The behavior of placeableFileTypes is the same -- 0 items. Hm. Somehow I thought I did see that list. Perhaps it was a version earlier, "way back when Stuff actually worked".)

     

    Anyway, as far as the OP is concerned: perhaps it's easiest to build a dictionary of most-frequently-used extensions to associate the mime type with. That can be as easy as this (implementation details depend on what the mime type is actually used for):

     

    // from http://www.webmaster-toolkit.com/mime-types.shtml
    var mimetype = {
    jpg:'image/jpeg',
    jpe:'image/jpeg',
    jpeg:'image/jpeg',
    png:'image/png',
    pdf:'application/pdf'
    };
    imgs = app.activeDocument.allGraphics;
    result = [];
    for (i=0; i<imgs.length; i++)
    result.push (imgs[i].itemLink.filePath+' = '+mimetype[String(imgs[i].itemLink.filePath.match(/[^.]+$/)).toLowerCase()]);
    alert (result.join('\r'));
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 6:58 AM   in reply to Peter Kahrel

    @Peter – it might be broken in InDesign CS6, but you can use it in CS5.5:

     

    app.placeableFileTypes.length;
    //Result for CS5.5: 60
     
    app.placeableFileExtensions.length;
    //Result for CS5.5: 68
    

     

     

    InDesign CS5.5 v7.5.3 on OSX 10.6.8

     

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 7:03 AM   in reply to Laubender

    Uwe,

     

    Yet another Mac-Win difference. ID 7.5.3 on Windows 7:

     

    app.placeableFileTypes.length;

    //Result for CS5.5: 0

     

    app.placeableFileExtensions.length;

    //Result for CS5.5: 67

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 7:42 AM   in reply to Peter Kahrel

    @Peter – Indesign CS5.5 v7.5.3 on OSX 10.6.8:

     

    app.placeableFileTypes:
    sDnI, sMdI, dDnI, 3dDI, 4dDI, 5dDI, 6dDI, 7dDI, 2dDI, t5DI, t6DI, t7DI, t2DI, 3DCI, 
    5xCI, 2xCI,  3PM, EVAW, WALU, FFIA, LV4F, LVLF, LFWS, GEPM, aGPM, vGPM, 
    xGPM, , VooM, xcod, 8SLX,  FTR, NB8W, NBDW, xslx, TXET, txtu, TXET, FSPE, PSPE, 
    TXET, FTCP, PTCP, TCIP, FFMW, PFMW, TXET,  FDP, fGNP, SPB8,  XCP,  PMB, 
     ELR, fFIG, TC.., FFIT,  1PT, GEPJ, FIFJ, GPJp
     
    app.placeableFileExtensions:
    inds, idms, indd, indt, incd, incx, icml, mp3, WAV, WAVE, AU, AIF, AIFF, F4V, 
    MP4, FLV, SWF, MPG, M15, M1A, M1V, M64, MP2, MPA, MPM, MPV, M1S, M75, 
    MPEG, AVI, MOV, docx, xls, rtf, doc, doc, xlsx, txt, utxt, TXT, EPS, AI, TRP, DCS, 
    PMG, PCT, PIC, WMF, EMF, joboptions, pdf, pdp, PNG, PSD, PDD, PCX, PCC, 
    BMP, RLE, GIF, SCT, CT, TIF, TIFF, TP1, JPG, JPEG, JPE
    

     

    Note:

    empty array element between "xGPM" and "VooM"

     

    first blank in " 3PM", " FTR", " FDP", " XCP", " PMB", " ELR" and " 1PT"

     

    and the two dots in "TC.."

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 8:11 AM   in reply to Laubender

    Aargh! I was sure I saw the 'file types' list somewhere -- now it comes back to me, like yesterday's dinner.

     

    't Was on my Mac; "File Type" is a Mac Thing Only.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points