9 Replies Latest reply: Aug 3, 2012 9:13 AM by lanejd RSS

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

    lanejd

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

        • 1. Re: JS - How do I Find the MIME type of a Link?
          [Jongware] CommunityMVP

          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.)

          • 2. Re: JS - How do I Find the MIME type of a Link?
            [Jongware] CommunityMVP

            [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#placeableFileExtensions and placeableFileTypes immediately below.

            • 3. Re: JS - How do I Find the MIME type of a Link?
              pkahrel Community Member

              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

              • 4. Re: JS - How do I Find the MIME type of a Link?
                [Jongware] CommunityMVP

                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'));
                
                • 5. Re: JS - How do I Find the MIME type of a Link?
                  Laubender CommunityMVP

                  @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

                  • 6. Re: JS - How do I Find the MIME type of a Link?
                    pkahrel Community Member

                    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

                    • 7. Re: JS - How do I Find the MIME type of a Link?
                      Laubender CommunityMVP

                      @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

                      • 8. Re: JS - How do I Find the MIME type of a Link?
                        [Jongware] CommunityMVP

                        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.

                        • 9. Re: JS - How do I Find the MIME type of a Link?
                          lanejd Community Member

                          Thank you very much. You guys are AWESOME!