And for those of you who just want to see the whole darn shooting match, here it is…if you can think of a better way to accomplish any of this, let me know.
I will eventually move this to Code Exchange after I do some more review on my own. I will post this in a no-GUI version (basically as below) and the fancier release version with a nicer GUI (like progress bars) using FaceSpan (my next development step).
What this script does is take most common graphic design files types and fixes their Type, Creator, and Preview as applicable, including fixing file extensions. It is the end result of alot of research on how to repair Mac files that had their Resource forks stripped by being stored on a Windows-based asset management system…an issue which we did not see until it was entirely too late. Doh!
For reference: the Mac OS itself is terrible at guessing file type and creator on it’s own in the absence of the resource fork, and isn’t smart enough to detect improper extensions, or even tell the difference between a PDF file and a native Illustrator file. This software relies on GREP to parse the guts of a given file looking for clues on what the file really is, based on hours of my own research. Over 40 possible combinations are covered, not including basic version detection (a feature not directly used…yet…but provided in the logs anyway).
This is Version 2 (version 1 is in Code Exchange already)…makes some significant speed and efficiency improvements thanks to you folks here at MacScriper (see comments…credit where credit is due!), and fixes some subtleties not accounted for in Version 1 (like telling the difference between a PDF and a native AI file in the absence of a file extension).
Credit to my managers for allowing me to allow my efforts free in the wild for anyone who wants it. Big companies don’t do that often.
--
-- DECLARE PROPERTIES
--
-- debugging on?
property g_debug : true
--basic file path and names
property g_home_folder_path : path to home folder
property g_log_file_name : "Clorox File Repair Log.txt"
--Native Illustrator and PDF files (need to be checked against together due to nearly exact header structure)
property g_extensions_illustrator_native : {"none", ".ai", ".eps", ".pdf"} --CCM sometimes adds ".eps" or PDF when it doesn't see an extension...doh!
property g_headers_illustrator_native_version : {"Creator:Adobe Illustrator(TM) 3.2", "Creator: Adobe Illustrator(R) 8", "Creator: Adobe Illustrator(R) 9", "Creator: Adobe Illustrator(R) 10", "Creator: Adobe Illustrator(R) 11", "Creator: Adobe Illustrator(R) 12"}
property g_extensions_pdf : {".pdf"}
property g_headers_pdf_version : {"%PDF-1.3.%", "%PDF-1.4.%", "%PDF-1.5.%", "%PDF-1.6.%"} --PDF versions 4, 5, 6, and 7 in that order
property g_headers_pdf_valid : {"AIPDFPrivateData"} --true Illustrator files will not contain this string or use "AIPrivateData" for versions 9 and above
--Illustrator EPS files
property g_extensions_illustrator_eps : {".eps", ".epsf"}
property g_headers_illustrator_eps : {"PS-Adobe-2.0 EPSF-", "PS-Adobe-3.0 EPSF-", "PS-Adobe-3.1 EPSF-"} --valid Illustrator EPS files have this additional header info
property g_headers_illustrator_eps_version : {"Creator:Adobe Illustrator(TM) 3.2", "Creator: Adobe Illustrator(R) 8", "Creator: Adobe Illustrator(R) 9", "Creator: Adobe Illustrator(R) X", "Creator: Adobe Illustrator(R) 11", "Creator: Adobe Illustrator(R) 12"}
--Freehand EPS files
property g_extensions_freehand_eps : {".eps"}
property g_headers_freehand_eps : {"PS-Adobe-2.0 EPSF-"} --valid Freehand EPS files have this additional header info
property g_headers_freehand_version : {"Creator: FreeHand 8", "Creator: FreeHand 7", "Creator: FreeHand MX 11"}
--Photoshop EPS files
property g_extensions_photoshop_eps : {".eps", ".epsf", ".dcs", ".eps_lr", ".eps_hr", ".dcs_lr", ".dcs_hr"}
property g_headers_photoshop_eps : {"Creator: Adobe Photoshop Version 6", "Creator: Adobe Photoshop Version 7", "Creator: Adobe Photoshop Version 8", "Creator: Adobe Photoshop Version 9", "Creator: MediaBin"}
--Photoshop PSD files
property g_extensions_photoshop_psd : {".psd", ".psd_lr", ".psd_hr"}
property g_headers_photoshop_psd : {"Adobe Photoshop 7", "Adobe Photoshop CS Macintosh", "Adobe Photoshop CS2 Macintosh", "8BIM"} -- "8BIM" in header all Photoshop headers 6+...check last since 7 through CS2 detection can be specific
--Photoshop TIF files
property g_extensions_photoshop_tif : {".tif", ".tiff", ".tif_lr", ".tif_hr"}
property g_headers_photoshop_tif : {"Adobe Photoshop 7", "Adobe Photoshop CS Macintosh", "Adobe Photoshop CS2 Macintosh"}
--Photoshop JPG files
property g_extensions_photoshop_jpg : {".jpg", ".jpeg"}
property g_headers_photoshop_jpg : {"Adobe Photoshop 7", "Adobe Photoshop CS Macintosh", "Adobe Photoshop CS2 Macintosh"}
--Photoshop PNG files
property g_extensions_photoshop_png : {".png"}
--Photoshop GIF files
property g_extensions_photoshop_gif : {".gif"}
--InDesign files
property g_extensions_indesign : {"none", ".indd"}
property g_headers_indesign : {"CreatorTool>Adobe InDesign 3", "CreatorTool>Adobe InDesign 4", "Adobe InDesign"} --InDesign 2 header overlaps versions 3 and 4, so check for it last
--Quark Xpress files
property g_extensions_quark : {"none", ".qxd", ".qxp"}
property g_headers_quark : {"MMXPR3.A.AD", "MMXPR3.B.BD", "MMXPR3.C.CX", "MMXPR3 D DX"} --Quark 4, 5, 6, and 7 in that order
--Freehand files
property g_extensions_freehand : {"none", ".fh3", ".fh4", ".fh5", ".fh7", ".fh8", ".fh9", ".fh10", ".fh11"}
property g_headers_freehand : {"AGD1", "AGD2", "AGD3", "FreeHand10", "FreeHand11"}
--Pagemaker files (no unique headers available)
property g_extensions_pagemaker : {".pm5", ".pm6", ".p65"}
--UNIX executables
property g_extensions_unix : {"none"}
property g_headers_unix : {"PAGEZERO"}
--
-- UTILITY HANDLERS
--
--Log Entry Generation
-- With help from StephanK of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=76607#p76607
--
on logMe(log_string, indent_level)
if g_debug is true then --allows turning the debugger on and off so my logMe's can be left in final version
set log_target to (g_home_folder_path & "Library:Logs:" & g_log_file_name) as text
try
set log_file_ref to open for access file log_target with write permission
repeat indent_level times
write tab to log_file_ref starting at eof
end repeat
write ((log_string as text) & return) to log_file_ref starting at eof
close access log_file_ref
return true
on error
try
close access file log_target
end try
return false
end try
end if
end logMe
-- Finder comment editor
--
on finderCommenter(path_to_file, add_this_text)
tell application "Finder"
set existing_comments to (comment of path_to_file)
--check for existing comments
if existing_comments = "" then
set new_comments to add_this_text
else
set new_comments to existing_comments & return & add_this_text
end if
--write updated comments
set comment of path_to_file to new_comments
end tell
end finderCommenter
-- Date stamp generator
-- with help from StefanK of MacScripter
-- http://bbs.applescript.net/viewtopic.php?id=20420
--
on dateStamp()
-- Load date components from system
tell (current date)
set dayStamp to day
set monthStamp to (its month as integer)
set yearStamp to year
end tell
--coerce components to two-digit form
set dayStamp to (text -2 thru -1 of ("0" & dayStamp as string))
set monthStamp to (text -2 thru -1 of ("0" & monthStamp as string))
set yearStamp to (text 3 thru 4 of (yearStamp as string))
--Assemble datestamp
return yearStamp & monthStamp & dayStamp as text
end dateStamp
--
-- INFORMATION GATHERING HANDLERS
--
-- Determines "real" extension
-- with help from Jacques of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=76649#p76649
--
on extensionFinder(file_path)
--default finder info
tell (info for file_path without size) to set {file_name, file_extension} to {name, name extension}
if file_extension is not missing value then
--the finder recognizes the _lr/_hr style extensions just fine,
--use that to get the name without the extension the Finder sees
set file_name to text 1 thru -((count file_extension) + 2) of file_name
--check the file name to see if it still contains a CADS extension and
--the one the Finder saw was the false one added by MediaBin
tell file_name
if length > 6 and character -7 is "." then
if it ends with "_lr" or it ends with "_hr" then
set file_extension to text -6 thru -1
set file_name to text 1 thru -8
end if
end if
end tell
return {"." & file_extension, file_name}
else
set file_extension to "none"
return {file_extension, file_name}
end if
end extensionFinder
-- Uses GREP to look into file looking for header string to identify file
--
on grepForString(path_to_grep, search_list)
my logMe("BEGIN grepForString Handler", 3)
repeat with current_grep_item in search_list
try
set grep_result to grepMe(path_to_grep, current_grep_item)
exit repeat
on error
set grep_result to 0
end try
end repeat
if grep_result = 0 then
set current_grep_item to "<nothing found>"
end if
my logMe("¢ RETURN: " & grep_result & "x | " & current_grep_item, 3)
my logMe("END grepForString Handler", 3)
return {grep_result, current_grep_item as Unicode text}
end grepForString
-- Uses GREP to parse a single instance for grepForString
-- Sub-handling this gets around AppleScript problem when GREP returns zero
--
on grepMe(file_path, search_item)
set file_path_POSIX to POSIX path of file_path
set shell_string to ("grep -ch \"" & search_item & "\" " & quoted form of file_path_POSIX)
return (do shell script shell_string)
end grepMe
--
-- FILE DETECTION SUB-HANDLERS
--
-- Am I a native Illustrator or an Acrobat PDF file?
--
on amI_AIorPDF(file_path, file_extension)
my logMe("BEGIN amI_AIorPDF handler", 2)
--Is it even possible I am an Illustrator of PDF at all?
if (file_extension is in g_extensions_illustrator_native) or (file_extension is in g_extensions_pdf) then
--I'm either Illustrator or PDF, which am I? (based on AIPDF search)
set header_grep to grepForString(file_path, g_headers_pdf_valid)
if item 1 of header_grep is greater than 0 then
--I'm a PDF file
my logMe("¢ PDF file found", 2)
--what version?
set header_grep to grepForString(file_path, g_headers_pdf_version)
if item 2 of header_grep is "%PDF-1.6.%" then
my logMe("¢ Version: 7", 2)
else if item 2 of header_grep is "%PDF-1.5.%" then
my logMe("¢ Version: 6", 2)
else if item 2 of header_grep is "%PDF-1.4.%" then
my logMe("¢ Version: 5", 2)
else if item 2 of header_grep is "%PDF-1.3.%" then
my logMe("¢ Version: 6", 2)
end if
--all PDF files use the same File Type, File Creator, and Extension
set file_type to "PDF "
set file_creator to "CARO"
set file_extension to ".pdf"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_AIorPDF handler", 2)
return {file_type, file_creator, file_extension}
else
--Am I a native Illustrator file or an EPS file? (MediaBin sometimes adds ".eps" to end of native Illustrator files)
set header_grep to grepForString(file_path, g_headers_illustrator_eps)
if item 1 of header_grep is 0 then
--Am I native Illustrator file?
set header_grep to grepForString(file_path, g_headers_illustrator_native_version)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Illustrator file found", 2)
--what version?
--these checks are out of numerical order because we didn't use Illustrator 9 or 10 much, so the versions we used more are checked first
if item 2 of header_grep is "Creator: Adobe Illustrator(R) 12" then
my logMe("¢ Version: 12 (CS2)", 2)
set file_type to "PDF "
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 11" then
my logMe("¢ Version: 11 (CS2)", 2)
set file_type to "PDF "
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 8" then
my logMe("¢ Version: 8", 2)
set file_type to "TEXT"
else if item 2 of header_grep is "Creator:Adobe Illustrator(TM) 3.2" then
my logMe("¢ Version: 3.2", 2)
set file_type to "TEXT"
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 9" then
my logMe("¢ Version: 9", 2)
set file_type to "PDF "
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 10" then
my logMe("¢ Version: 10", 2)
set file_type to "PDF "
end if
--all Illustrator files have the same Creator and Extension
set file_creator to "ART5"
set file_extension to ".ai"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_AIorPDF handler", 2)
return {file_type, file_creator, file_extension}
else
--not an Illustrator or EPS file (no extension clause)
my logMe("¢ Not a native Illustrator or PDF file", 2)
my logMe("END amI_AIorPDF handler", 2)
return {}
end if
else
--I'm probably an EPS file, not Illustrator
my logMe("¢ This is probably an EPS file.", 2)
my logMe("END amI_AIorPDF handler", 2)
return {}
end if
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_AIorPDF handler", 2)
return {}
end if
end amI_AIorPDF
-- Am I an Illustrator EPS file?
--
on amI_AIeps(file_path, file_extension)
my logMe("BEGIN amI_AIeps handler", 2)
--Is it even possible I am an Illustrator EPS at all (extension check)?
if file_extension is in g_extensions_illustrator_eps then
--The proper extension does not necessarily mean it's an Illustrator EPS, check basic header info
set header_grep to grepForString(file_path, g_headers_illustrator_eps)
if item 1 of header_grep is greater than 0 then
--May or may not be an EPS file generated by Illustrator (could be FreeHand or Photoshop, for example)
set header_grep to grepForString(file_path, g_headers_illustrator_eps_version)
if item 1 of header_grep is greater than 0 then
--what version?
--these checks are our of numerical order because we didn't use Illustrator 9 or 10 much, so the versions we used more are checked first
if item 2 of header_grep is "Creator: Adobe Illustrator(R) 12" then
my logMe("¢ Version: 12 (CS2)", 2)
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 11" then
my logMe("¢ Version: 11 (CS1)", 2)
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 8" then
my logMe("¢ Version: 8", 2)
else if item 2 of header_grep is "Creator:Adobe Illustrator(TM) 3.2" then
my logMe("¢ Version: 3.2", 2)
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) 9" then
my logMe("¢ Version: 9", 2)
else if item 2 of header_grep is "Creator: Adobe Illustrator(R) X" then --note how "X" is used instead of "10" for EPS files
my logMe("¢ Version: 10", 2)
end if
--all Illustrator EPS files use the same File Type, File Creator, and Extension
set file_type to "EPSF"
set file_creator to "ART5"
set file_extension to ".eps"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_AIeps handler", 2)
return {file_type, file_creator, file_extension}
else
--not an Illustrator EPS file
my logMe("¢ Not an Illustrator EPS file (version check)", 2)
my logMe("END amI_AIeps handler", 2)
return {}
end if
else
--not an Illustrator EPS file
my logMe("¢ Not an Illustrator EPS file (%PDF check)", 2)
my logMe("END amI_AIeps handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_AIeps handler", 2)
return {}
end if
end amI_AIeps
-- Am I an Freehand EPS file?
-- (checking these after the AI EPS, even though they are rare, to get all the EPS checks out of the way)
--
on amI_FHeps(file_path, file_extension)
my logMe("BEGIN amI_FHeps handler", 2)
--Is it even possible I am an Illustrator EPS at all (extension check)?
if file_extension is in g_extensions_freehand_eps then
--No extension does not necessarily mean it's an Freehand EPS, check header
set header_grep to grepForString(file_path, g_headers_freehand_eps)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Freehand EPS file found", 2)
--May or may not be an EPS file generated by Freehand (could be Photoshop for example)
set header_grep to grepForString(file_path, g_headers_freehand_version)
if item 1 of header_grep is greater than 0 then
--version detection
if item 2 of header_grep is "Creator: FreeHand 7" then
my logMe("¢ Version: 7", 2)
set file_creator to "FH70"
else if item 2 of header_grep is "Creator: FreeHand 8" then
my logMe("¢ Version: 8", 2)
set file_creator to "FH80"
else if item 2 of header_grep is "Creator: FreeHand MX 11" then
my logMe("¢ Version: MX 11", 2)
set file_creator to "FH11"
end if
--all Freehand EPS files use the same file type and extension
set file_type to "EPSF"
set file_extension to ".eps"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_FHeps handler", 2)
return {file_type, file_creator, file_extension}
else
--not an Illustrator EPS file
my logMe("¢ Not an Freehand EPS file (version check)", 2)
my logMe("END amI_FHeps handler", 2)
return {}
end if
else
--not an Freehand EPS file
my logMe("¢ Not a Freehand EPS file (%PDF check)", 2)
my logMe("END amI_FHeps handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_FHeps handler", 2)
return {}
end if
end amI_FHeps
-- Am I an Photoshop (bitmap) EPS file?
-- (default all bitmapped EPS files to open in Photoshop)
--
on amI_PhotoshopEPS(file_path, file_extension)
my logMe("BEGIN amI_PhotoshopEPS handler", 2)
--Is it even possible I am aPhotoshop EPS at all (extension check)?
if file_extension is in g_extensions_photoshop_eps then
--Proper extension does not necessarily mean it's a Photoshop EPS, check header
set header_grep to grepForString(file_path, g_headers_photoshop_eps)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Photoshop EPS file found", 2)
--version detection
if item 2 of header_grep is "Creator: Adobe Photoshop Version 6" then
my logMe("¢ Version: 6", 2)
else if item 2 of header_grep is "Creator: Adobe Photoshop Version 7" then
my logMe("¢ Version: 7", 2)
else if item 2 of header_grep is "Creator: Adobe Photoshop Version 8" then
my logMe("¢ Version: 8 (CS1)", 2)
else if item 2 of header_grep is "Creator: Adobe Photoshop Version 9" then
my logMe("¢ Version: 9 (CS2)", 2)
end if
--all Photoshop EPS files use the same file type and creator type
set file_type to "EPSF"
set file_creator to "8BIM"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_PhotoshopEPS handler", 2)
return {file_type, file_creator, file_extension}
else
--not a Photoshop EPS file
my logMe("¢ Not a Photoshop EPS file ", 2)
my logMe("END amI_PhotoshopEPS handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_PhotoshopEPS handler", 2)
return {}
end if
end amI_PhotoshopEPS
-- Am I an Photoshop PSD file?
--
on amI_PhotoshopPSD(file_path, file_extension)
my logMe("BEGIN amI_PhotoshopPSD handler", 2)
--Is it even possible I am a Photoshop PSD at all (extension check)?
if file_extension is in g_extensions_photoshop_psd then
--Proper extension does not necessarily mean it's a Photoshop PSD, check header
set header_grep to grepForString(file_path, g_headers_photoshop_psd)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Photoshop PSD file found", 2)
--version detection
if item 2 of header_grep is "Adobe Photoshop 7" then
my logMe("¢ Version: 7", 2)
else if item 2 of header_grep is "Adobe Photoshop CS Macintosh" then
my logMe("¢ Version: 8 (CS1)", 2)
else if item 2 of header_grep is "Adobe Photoshop CS2 Macintosh" then
my logMe("¢ Version: 9 (CS2)", 2)
else if item 2 of header_grep is "8BIM" then --must check last since all versions have "8BIM" in header
my logMe("¢ Version: pre-7", 2)
end if
--all Photoshop PSD files use the same file type and creator type
set file_type to "8BPS"
set file_creator to "8BIM"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_PhotoshopPSD handler", 2)
return {file_type, file_creator, file_extension}
else
--not a Photoshop EPS file
my logMe("¢ Not a Photoshop PSD file ", 2)
my logMe("END amI_PhotoshopPSD handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_PhotoshopPSD handler", 2)
return {}
end if
end amI_PhotoshopPSD
-- Am I an Photoshop TIF file?
--
on amI_PhotoshopTIF(file_path, file_extension)
my logMe("BEGIN amI_PhotoshopTIF handler", 2)
--Is it even possible I am a Photoshop TIF at all (extension check)?
if file_extension is in g_extensions_photoshop_tif then
--Proper extension does not necessarily mean it's a Photoshop TIF, check header
set header_grep to grepForString(file_path, g_headers_photoshop_tif)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Photoshop TIF file found", 2)
--version detection
if item 2 of header_grep is "Adobe Photoshop 7" then
my logMe("¢ Version: 7", 2)
else if item 2 of header_grep is "Adobe Photoshop CS Macintosh" then
my logMe("¢ Version: 8 (CS1)", 2)
else if item 2 of header_grep is "Adobe Photoshop CS2 Macintosh" then
my logMe("¢ Version: 9 (CS2)", 2)
end if
--all Photoshop TIF files use the same file type and creator type
set file_type to "TIFF"
set file_creator to "8BIM"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_PhotoshopTIF handler", 2)
return {file_type, file_creator, file_extension}
else
--not a Photoshop TIF file
my logMe("¢ Not a Photoshop TIF file ", 2)
my logMe("END amI_PhotoshopTIF handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_PhotoshopTIF handler", 2)
return {}
end if
end amI_PhotoshopTIF
-- Am I an Photoshop JPG file?
--
on amI_PhotoshopJPG(file_path, file_extension)
my logMe("BEGIN amI_PhotoshopJPG handler", 2)
--Is it even possible I am a Photoshop JPG at all (extension check)?
if file_extension is in g_extensions_photoshop_jpg then
--Proper extension does not necessarily mean it's a Photoshop JPG, check header
set header_grep to grepForString(file_path, g_headers_photoshop_jpg)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Photoshop JPG file found", 2)
--version detection
if item 2 of header_grep is "Adobe Photoshop 7" then
my logMe("¢ Version: 7", 2)
else if item 2 of header_grep is "Adobe Photoshop CS Macintosh" then
my logMe("¢ Version: 8 (CS1)", 2)
else if item 2 of header_grep is "Adobe Photoshop CS2 Macintosh" then
my logMe("¢ Version: 9 (CS2)", 2)
end if
--all Photoshop JPG files use the same file type and creator type
set file_type to "JPEG"
set file_creator to "8BIM"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_PhotoshopJPG handler", 2)
return {file_type, file_creator, file_extension}
else
--not a Photoshop JPG file
my logMe("¢ Not a Photoshop JPG file ", 2)
my logMe("END amI_PhotoshopJPG handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_PhotoshopJPG handler", 2)
return {}
end if
end amI_PhotoshopJPG
-- Am I a Photoshop PNG file?
--
on amI_PhotoshopPNG(file_path, file_extension)
my logMe("BEGIN amI_PhotoshopPNG handler", 2)
--Is it even possible I am a Photoshop PNG at all (extension check)?
if file_extension is in g_extensions_photoshop_png then
--all Photoshop PNG files use the same file type and creator type
set file_type to "PNGf"
set file_creator to "8BIM"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_PhotoshopPNG handler", 2)
return {file_type, file_creator, file_extension}
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_PhotoshopPNG handler", 2)
return {}
end if
end amI_PhotoshopPNG
-- Am I an Photoshop GIF file?
--
on amI_PhotoshopGIF(file_path, file_extension)
my logMe("BEGIN amI_PhotoshopGIF handler", 2)
--Is it even possible I am a Photoshop GIF at all (extension check)?
if file_extension is in g_extensions_photoshop_gif then
--all Photoshop GIF files use the same file type and creator type
set file_type to "GIFf"
set file_creator to "8BIM"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_PhotoshopGIF handler", 2)
return {file_type, file_creator, file_extension}
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_PhotoshopGIF handler", 2)
return {}
end if
end amI_PhotoshopGIF
-- Am I an InDesign file?
--
on amI_InDesign(file_path, file_extension)
my logMe("BEGIN amI_InDesign handler", 2)
--Is it even possible I am an InDesign file at all (extension check)?
if file_extension is in g_extensions_indesign then
--Proper extension does not necessarily mean it's a InDesign, check header
set header_grep to grepForString(file_path, g_headers_indesign)
if item 1 of header_grep is greater than 0 then
my logMe("¢ InDesign file found", 2)
--version detection
if item 2 of header_grep is "CreatorTool>Adobe InDesign 3" then
my logMe("¢ Version: 3 (CS1)", 2)
set file_type to "IDd3"
else if item 2 of header_grep is "CreatorTool>Adobe InDesign 4" then
my logMe("¢ Version: 4 (CS2)", 2)
set file_type to "IDd4"
else if item 2 of header_grep is "Adobe InDesign" then
my logMe("¢ Version: 2", 2)
set file_type to "InDd"
end if
--all InDesign files use the same creator type and extension
set file_creator to "InDn"
set file_extension to ".indd"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_InDesign handler", 2)
return {file_type, file_creator, file_extension}
else
--not an InDesign file
my logMe("¢ Not an InDesign file ", 2)
my logMe("END amI_InDesign handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_InDesign handler", 2)
return {}
end if
end amI_InDesign
-- Am I a Quark XPress file?
--
on amI_Quark(file_path, file_extension)
my logMe("BEGIN amI_Quark handler", 2)
--Is it even possible I am an Quark XPress file at all (extension check)?
if file_extension is in g_extensions_quark then
--Proper extension does not necessarily mean it's a Quark XPress, check header
set header_grep to grepForString(file_path, g_headers_quark)
if item 1 of header_grep is greater than 0 then
my logMe("¢ Quark XPress file found", 2)
--version detection
if item 2 of header_grep is "MMXPR3.A.AD" then
my logMe("¢ Version: 4", 2)
set file_type to "XDOC"
else if item 2 of header_grep is "MMXPR3.B.BD" then
my logMe("¢ Version: 5", 2)
set file_type to "XDOC"
else if item 2 of header_grep is "MMXPR3.C.CX" then
my logMe("¢ Version: 6", 2)
set file_type to "XPRJ"
else if item 2 of header_grep is "MMXPR3 D DX" then
my logMe("¢ Version: 7", 2)
set file_type to "XPRJ"
end if
--all Quark XPress files use the same creator type
set file_creator to "XPR3"
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_Quark handler", 2)
return {file_type, file_creator, file_extension}
else
--not an Quark XPress file
my logMe("¢ Not an Quark XPress file ", 2)
my logMe("END amI_Quark handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_Quark handler", 2)
return {}
end if
end amI_Quark
-- Am I a Freehand file?
--
on amI_Freehand(file_path, file_extension)
my logMe("BEGIN amI_FreeHand handler", 2)
--Is it even possible I am an Freehand file at all (extension check)?
if file_extension is in g_extensions_freehand then
set header_grep to grepForString(file_path, g_headers_freehand)
--version detection
if (file_extension is ".fh11") or (item 2 of header_grep is "FreeHand11") then
my logMe("¢ Version: 11", 2)
set file_type to "AGD6"
set file_creator to "FH11"
set file_extension to ".fh11"
else if (file_extension is ".fh10") or (item 2 of header_grep is "FreeHand10") then
my logMe("¢ Version: 10 (X)", 2)
set file_type to "AGD5"
set file_creator to "FH10"
set file_extension to ".fh10"
else if (file_extension is ".fh9") then
my logMe("¢ Version: 9", 2)
set file_type to "AGD4"
set file_creator to "FH90"
set file_extension to ".fh9"
else if (file_extension is ".fh8") or (item 2 of header_grep is "AGD3") then
my logMe("¢ Version: 8", 2)
set file_type to "AGD3"
set file_creator to "FH80"
set file_extension to ".fh8"
else if (file_extension is ".fh7") or (item 2 of header_grep is "AGD2") then
my logMe("¢ Version: 7", 2)
set file_type to "AGD2"
set file_creator to "FH70"
set file_extension to ".fh7"
else if (file_extension is ".fh5") or (item 2 of header_grep is "AGD1") then
my logMe("¢ Version: 5", 2)
set file_type to "AGD1"
set file_creator to "FH50"
set file_extension to ".fh5"
else if (file_extension is ".fh4") then
my logMe("¢ Version: 4", 2)
set file_type to "AGD1"
set file_creator to "FH40"
set file_extension to ".fh4"
else if (file_extension is ".fh3") then
my logMe("¢ Version: 3", 2)
set file_type to "FHD3"
set file_creator to "FHA3"
set file_extension to ".fh3"
else
--not a Freehand file
my logMe("¢ Not a Freehand file ", 2)
my logMe("END amI_Freehand handler", 2)
return {}
end if
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_FreeHannd handler", 2)
return {file_type, file_creator, file_extension}
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_FreeHand handler", 2)
return {}
end if
end amI_Freehand
-- Am I a Pagemaker file?
--
on amI_Pagemaker(file_path, file_extension)
my logMe("BEGIN amI_Pagemaker handler", 2)
--Is it even possible I am an Pagemaker file at all (extension check)?
if file_extension is in g_extensions_pagemaker then
--version detection
if file_extension is ".pm5" then
my logMe("¢ Version: 5", 2)
set file_type to "ALB5"
set file_creator to "ALD5"
set file_extension to ".pm5"
else if file_extension is ".pm6" then
my logMe("¢ Version: 6", 2)
set file_type to "ALB6"
set file_creator to "ALD6"
set file_extension to ".pm6"
else if file_extension is ".p65" then
my logMe("¢ Version: 6.5", 2)
set file_type to "AB65"
set file_creator to "AD65"
set file_extension to ".p65"
else
--not a Pagemaker file
my logMe("¢ Not a Pagemaker file ", 2)
my logMe("END amI_Pagemaker handler", 2)
return {}
end if
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_FreeHannd handler", 2)
return {file_type, file_creator, file_extension}
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_Pagemaker handler", 2)
return {}
end if
end amI_Pagemaker
-- Am I a real UNIX executable?
-- Courtesy of Adam Bell of Macscripter
-- http://bbs.applescript.net/viewtopic.php?pid=71705#p71705
--
on amI_UNIX(file_path, file_extension)
my logMe("BEGIN amI_UNIX handler", 2)
--Is it even possible I am a UNIX executable at all (extension check)?
if file_extension is in g_extensions_unix then
--No extension does not necessarily mean it's a UNIX executable, check header
set header_grep to grepForString(file_path, g_headers_unix)
if item 1 of header_grep is greater than 0 then
my logMe("¢ UNIX executable found", 2)
--don't touch the file any further
set file_type to "<ignore>"
set file_creator to "<ignore>"
set file_extension to "<ignore>"
--remove red file label to show something was done
tell application "Finder" to set label index of path_to_fix to "0" as text
my logMe("¢ RETURN: " & file_type & " | " & file_creator & " | " & file_extension, 2)
my logMe("END amI_UNIX handler", 2)
return {file_type, file_creator, file_extension}
else
--not an Illustrator or EPS file (no extension clause)
my logMe("¢ Not a UNIX executable file", 2)
my logMe("END amI_UNIX handler", 2)
return {}
end if
else
my logMe("¢ No valid extensions.", 2)
my logMe("END amI_UNIX handler", 2)
return {}
end if
end amI_UNIX
-- what kind of file is it?
--
on fileDetective(path_to_check)
my logMe("BEGIN fileDetective handler", 1)
set file_info to {} --file type, file creator, proper file extension, proper file name
set file_extension to (item 1 of extensionFinder(path_to_check)) --get correct extension
--
--START DETECTIVE WORK
--
--is it a native Illustrator file? (including CCM-added ".eps" extensions)
if file_info is {} then
set file_info to amI_AIorPDF(path_to_check, file_extension)
end if
--is it an Illustrator EPS file?
if file_info is {} then
set file_info to amI_AIeps(path_to_check, file_extension)
end if
--is it a FreeHand EPS document?
if file_info is {} then
set file_info to amI_FHeps(path_to_check, file_extension)
end if
--is it a bitmapped EPS (or DCS) document (default to Photoshop)?
if file_info is {} then
set file_info to amI_PhotoshopEPS(path_to_check, file_extension)
end if
--is it a Photoshop PSD document?
if file_info is {} then
set file_info to amI_PhotoshopPSD(path_to_check, file_extension)
end if
--is it a Photoshop TIF document?
if file_info is {} then
set file_info to amI_PhotoshopTIF(path_to_check, file_extension)
end if
--is it a JPEG document (default to Photoshop)?
if file_info is {} then
set file_info to amI_PhotoshopJPG(path_to_check, file_extension)
end if
--is it a PNG document (default to Photoshop)?
if file_info is {} then
set file_info to amI_PhotoshopPNG(path_to_check, file_extension)
end if
--Is it a GIF document (default to Photoshop)?
if file_info is {} then
set file_info to amI_PhotoshopGIF(path_to_check, file_extension)
end if
--is it an InDesign document?
if file_info is {} then
set file_info to amI_InDesign(path_to_check, file_extension)
end if
--is it a Quark Xpress document? (add Quark 7?)
if file_info is {} then
set file_info to amI_Quark(path_to_check, file_extension)
end if
--is it a FreeHand document?
if file_info is {} then
set file_info to amI_Freehand(path_to_check, file_extension)
end if
--is it a PageMaker document?
if file_info is {} then
set file_info to amI_Pagemaker(path_to_check, file_extension)
end if
--is it a real UNIX executable?
if file_info is {} then
set file_info to amI_UNIX(path_to_check, file_extension)
end if
--have all checks failed?
if file_info is {} then
my logMe("¢ ERROR: file not recognized", 1)
end if
my logMe("END fileDetective handler", 1)
return file_info
end fileDetective
--
-- FILE REPAIR HANDLERS
--
-- Fixes file type and creator
--
on tcRepair(path_to_fix, file_info)
my logMe("BEGIN tcRepair handler", 1)
if file_info is not {} then
tell application "Finder"
set file type of path_to_fix to (item 1 of file_info) as text
set creator type of path_to_fix to (item 2 of file_info) as text
--remove red file label to show something was done
set label index of path_to_fix to "0" as text
my logMe("¢ File Type and File Creator repaired.", 1)
end tell
my finderCommenter(path_to_fix, "¢ File info repaired")
else
my logMe("¢ ERROR: File Type or File Creator was not available", 1)
my logMe("¢ No changes were made", 1)
end if
my logMe("END tcRepair handler", 1)
end tcRepair
-- Fixes file extension
--
on nameRepair(path_to_fix, file_info)
my logMe("BEGIN nameRepair handler", 1)
tell application "Finder"
if (item 3 of file_info) is not "none" then
set new_name to (item 4 of file_info) & (item 3 of file_info)
else
set new_name to name of path_to_fix
end if
my logMe("¢ Current Finder Name: " & name of path_to_fix, 1)
my logMe("¢ Proposed New Name: " & new_name, 1)
if name of path_to_fix is not equal to new_name then
set name of path_to_fix to new_name
my logMe("¢ Name repaired", 1)
else
my logMe("¢ File name doesn't require repair", 1)
end if
--remove red file label to show something was done
set label index of path_to_fix to "0" as text
end tell
my logMe("END nameRepair handler", 1)
end nameRepair
--Restore bitmap file preview
on restorePreview(path_to_fix, file_info)
my logMe("BEGIN restorePreview handler", 1)
if item 3 of file_info is not ".gif" then
my logMe("¢ General preview needed", 1)
set script_location to (((path to desktop) as text) & "Create_General_Preview.js") --remove this when switching back to FaceSpan
(*
--locate JavaScript for Photoshop (FaceSpan, Mac OS X 10.3 or earlier)
set where_is_this_app to path to me
set package_contents to "Contents:Resources:Create_General_Preview.js"
set script_location to (where_is_this_app & package_contents) as string
*)
else
my logMe("¢ GIF file preview needed", 1)
set script_location to (((path to desktop) as text) & "Create_GIF_Preview.js") --remove this when switching back to FaceSpan
(*
--locate JavaScript for Photoshop (FaceSpan, Mac OS X 10.3 or earlier)
set where_is_this_app to path to me
set package_contents to "Contents:Resources:Create_GIF_Preview.js"
set script_location to (where_is_this_app & package_contents) as string
*)
end if
tell application "Adobe Photoshop CS2"
open (path_to_fix as alias)
--execute JavaScript control of Photoshop
--acquired with ScriptingListener plugin per Adobe guidelines
do javascript (script_location as alias)
end tell
my logMe("¢ Photoshop file preview restored", 1)
--remove red file label to show something was done
tell application "Finder"
set label index of path_to_fix to "0" as text
end tell
my logMe("END restorePreview handler", 1)
end restorePreview
--
-- MAIN SCRIPT
--
on open actionItems
set dropped_items to {}
set cfr_version to "test" --remove when back in FaceSpan
--remove folders from list
--
-- courtesy of Adam Bell of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=77739#p77739
--
repeat with current_actionItem in actionItems
tell application "Finder"
if (contents of current_actionItem as string) ends with ":" then
try
set dropped_items to dropped_items & (files of (entire contents of current_actionItem) as alias list)
on error -- only one file inside (works around bug)
set dropped_items to dropped_items & (files of (entire contents of current_actionItem) as alias as list)
end try
else
set dropped_items to dropped_items & current_actionItem
end if
end tell
end repeat
--start main script
my logMe("--------------------------------------------------", 0)
my logMe("Clorox File Repair Started", 0)
my logMe("Debugging Mode = " & g_debug, 0)
my logMe("--------------------------------------------------", 0)
--mark all files red first, so it's visually obvious what files got touched during the script
my logMe("Scanning provided files...", 0)
repeat with currently_coloring in dropped_items
tell application "Finder"
set label index of currently_coloring to "2"
end tell
my finderCommenter(currently_coloring, "Scanned by Clorox File Repair v" & cfr_version & " on " & dateStamp())
end repeat
--loop through file list
repeat with current_item in dropped_items
tell application "Finder" to set name_to_fix to current_item's name as string
my logMe(return & "Current File Being Fixed, name_to_fix: " & name_to_fix, 0)
--what kind of file is it?
set file_info to fileDetective(current_item)
--repair file type and creator?
if (file_info is not {}) and (item 1 of file_info is not "<ignore>") and (item 2 of file_info is not "<ignore>") then
tcRepair(current_item, file_info)
end if
--repair file name?
if (file_info is not {}) and (item 3 of file_info is not "<ignore>") then
set file_info to (file_info & item 2 of my extensionFinder(current_item)) --add "real" file name to file_info
tell (info for current_item without size) to set actual_name to name --get current Finder name
set proper_name to (item 4 of file_info & item 3 of file_info) --construct "real" name and "real" extension
nameRepair(current_item, file_info) --fix the file name
end if
--restore preview image? (pixel-based images only)
--
--check for null set (file not identified)
if file_info is not {} then
--check that file was identified as a Photoshop file
if (item 2 of file_info is "8BIM") then
restorePreview(current_item, file_info)
end if
end if
end repeat
my logMe("--------------------------------------------------", 0)
my logMe("Clorox File Repair Finished", 0)
my logMe("--------------------------------------------------", 0)
quit
end open