I have a conundrum with the latest Adobe Illustrator CS4 file format.
I wrote a utility called Clorox File Repair for our department and partners (and the general public, they kindly let me give it away as freeware) that repairs graphics files that have lost their Resource Fork.
Specifically their File Type, File Creator, and any embedded “preview” image vanishes. Due to various reasons, I can’t rely on the extensions being available or correct (i.e. AI files with no “.ai” or even “.ai” files with “.pdf” extensions).
Up through CS3 I’ve been using a detection routine that uses a GREP of the file itself looking for key strings checked against finder “-b” (do script file -b) information (which also can’t be relied on 100%). Clorox File Repair 3 works very well for everything but CS4 files.
The problem has become that while ever since at least CS2 the Adobe Illustrator File format has been based on the Acrobat file format, there where key differences detectable via GREP’ing for the right strings. However, CS4 has removed those differences and AI files (especially if saved with a “PDF Preview”) and actual PDF files look identical “under the hood.”
How you can help.
I need an AppleScript-able way to tell between an AI file and PDF file that is 100% reliable. It doesn’t have to be a single criteria”ideally it should be at least a 2-criteria check.
Right now I use “-b” Finder info and GREP, but an open to other scriptable, free tools”though I am loathe to require plug-ins when distributing as freeware or installing in our group (though we do use EXIFtools for another solution, so I’m open to ideas).
Reminder: AI vs. PDF is only the last hurdle. Using existing techniques it also fixes/recognizes other files like InDesign, FreeHand, older Illustrator, Photoshop, BarCodePro, etc. Just this one combo has me baffled.
Help?
Just a quick bump”no one has any ideas?
Did I finally find a level of esoterica the fine folks here haven’t crossed-into yet?
Maybe you could use a foundation tool, which tries to initialize a PDFDocument class with the given PDF file path. Depending on the result you could tell whether it is a PDF document or not. Just a thought before going to sleep
[code]#import <Foundation/Foundation.h>
#import <Quartz/Quartz.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *filePath = [userDefaults stringForKey:@"file"];
if (!filePath) {
printf("ERROR: Missing file path (-file)\n");
return 1;
}
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir;
if (![fileManager fileExistsAtPath:filePath isDirectory:&isDir]) {
printf("ERROR: The given file does not exist:\n\t%s", [filePath UTF8String]);
return 1;
} else {
if (isDir) {
printf("ERROR: The given file path points to a directory:\n\t%s", [filePath UTF8String]);
}
}
NSURL *fileURL = [NSURL fileURLWithPath];
PDFDocument *pdf = [[PDFDocument alloc] initWithURL:fileURL];
if (!pdf) {
printf("No PDF\n");
} else {
printf("PDF\n");
}
[pdf release];
[pool drain];
return 0;
}[/code]
eyes glaze over
Please explain slowly for the guy who knows AppleScript, FaceSpan, and some bare essential command line.
:o
Hi Kevin,
Reading your post I thought you were familiar with those kind of tools. Sorry, my mistake. I have written you a small sample droplet, which you can download here as a ZIP archive. The archive also contains the compiled command line utility, which should work on Mac OS X 10.4+.
When dropping files onto the droplet named PDF-Check it will display for each file whether it is a PDF or not. To do this, the called command line utility simply tries to initialize a PDFDocument object from the passed file path. If this fails, the given file is most probably not a PDF.
Well, give it a try
Best regards from Berlin
Martin
So how would I send a file to this utility with AppleScript (as part of a larger script)?
It’s all in the code of the short sample droplet Okay, here we go:
-- path to the command line utility
set toolpath to (((path to me) as text) & "Contents:Resources:pdfcheck")
set qtdtoolpath to quoted form of POSIX path of toolpath
-- building the command to be executed
set command to qtdtoolpath & " -file " & quoted form of POSIX path of pdffile
-- executing the command and processing/displaying the result
try
set output to (do shell script command)
if output is equal to "PDF" then
set infomsg to "File name: " & foundfilename & return & "PDF: Yes"
else if output is equal to "No PDF" then
set infomsg to "File name: " & foundfilename & return & "PDF: No"
end if
on error errmsg number errnum
set errmsg to "File: " & (foundfile as text) & return & return & errmsg
end try
Does this help?
Best regards,
Martin