I need to be able to find the MIME type of a linked item in InDesign. Is there a simple way to do this?
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.)
[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.
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
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'));
@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
North America
Europe, Middle East and Africa
Asia Pacific