Hi,
I wrote a small script here, the purpose of which is to determine the version of Adobe Illusrator that created a particular file (for example, such as “.eps” or “.ai”). It uses the free exiftool, available to everyone.
I am interested in How to do the same using AsObjC instead of exiftool?
My script:
-- script: get Creator Adobe Illustrator version of file
-- plain AppleScript solution
-- written: by KniazidisR, 25 December 2020
property exiftoolPath : "/usr/local/bin/exiftool"
set theAlias to choose file of type {"eps", "ai"}
set thePath to quoted form of (POSIX path of theAlias)
set creatorTool to do shell script exiftoolPath & " -s3 -CreatorTool " & thePath
set theCreator to do shell script exiftoolPath & " -s3 -Creator " & thePath
if "Adobe Illustrator" is in creatorTool then
return creatorTool
else if "Adobe Illustrator" is in theCreator then
return theCreator
else
display dialog "The chozen file is not created by Adobe Illustrator"
end if
There is no ASObjC equivalent. Depending on the version and file type, the info is stored in different places.
Thanks for the reply anyway.
I will attempt now to make my script more flexible:
-- script: check if the App is Creator of file (plain AppleScript solution)
-- written: by KniazidisR, 25 December 2020
-- The script attemps to return the best helper info in any case
-- The user can uncomment the display dialog lines
set exiftoolPath to "/usr/local/bin/exiftool" -- make your change here
set theToolKey to "Adobe Illustrator" -- make your change here
set theAlias to choose file
set thePath to quoted form of (POSIX path of theAlias)
set theInfo to my checkAppIsCreator(exiftoolPath, thePath, theToolKey)
on checkAppIsCreator(exiftoolPath, thePath, theToolKey)
try
set creatorTool to do shell script exiftoolPath & " -s3 -CreatorTool " & thePath
set theCreator to do shell script exiftoolPath & " -s3 -Creator " & thePath
set theSoftware to do shell script exiftoolPath & " -s3 -Software " & thePath
set mimeType to do shell script exiftoolPath & " -s3 -MIMEType " & thePath
ignoring case
if (theToolKey is in creatorTool) then
return creatorTool
else if (theToolKey is in theCreator) then
return theCreator
else if (theToolKey is in theSoftware) then
return theSoftware
else if (theToolKey is in mimeType) then
return mimeType
else
-- display dialog "The chozen file is not created by \"" & theToolKey & "\" Tool"
return {|Creator Tool|:creatorTool, |Creator|:theCreator, |Software|:theSoftware, |MIME type|:mimeType}
end if
end ignoring
on error
-- display dialog "The chosen file type is unknown to ExifTool"
return "Bad choice." & linefeed & "Please, choose other file."
end try
end checkAppIsCreator
Hi. This (or some variation) may work for your needs:
do shell script "awk 'BEGIN{ RS = \"\\r\" ; FS = \"\\n\" } /%%Creator: Adobe/ {print $0}' " & (choose file)'s POSIX path's quoted form
Hi Marc.
Your script is pretty cool, it successfully reports the version information of the file creator.
Note that I wrote my script in response to a request from one user. He is more interested in the Adobe suite identifier like CS3, CS6, etc. With a small set of IF checks, your script could produce similar information too.
But I would be more interested to know why my script returns one identifier for the next file, and yours returns 2
Thank you, Fredrik71.
This is the AsObjC code I was looking for. I just added support for EPS (Encapsulated PostScript) files to it. Now exiftool does not need to be installed:
use framework "Foundation"
use framework "Quartz"
use scripting additions
set theMessage to "Select a file:"
set theFile to (choose file of type {"pdf", "ai", "ait", "indd", "eps"} with prompt theMessage)
set theURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFile)
set theDoc to current application's PDFDocument's alloc()'s initWithURL:theURL
if (theDoc is not missing value) then
set theDict to (current application's NSMutableDictionary's alloc()'s initWithDictionary:(theDoc's documentAttributes())) as record
try
set theCreatorTool to {CreatorTool:(Creator of theDict)}
on error
try
set theProducer to {Producer:Producer of theDict}
end try
end try
else
set FileData to read theFile
if FileData contains "<xmp:CreatorTool>" then
--Separate the data by tag
set AppleScript's text item delimiters to {"<xmp:CreatorTool>", "</xmp:CreatorTool>"}
set FileDataBlocks to text items of FileData
set AppleScript's text item delimiters to ""
--Filedatablocks is a list; the metadata is usually item 2 in the list.
set theCreatorTool to {CreatorTool:(text item 2 of FileDataBlocks)}
else if FileData contains "%%Creator: " then
--Separate the data by tag
repeat with i from 1 to 10
set theParagraph to paragraph i of FileData
if theParagraph begins with "%%Creator: " then
set theCreator to {Creator:(text 12 thru -1 of theParagraph)}
return theCreator
end if
end repeat
end if
end if