Monday, April 22, 2019

#1 2019-04-06 11:58:25 pm

divster
Member
Registered: 2011-03-01
Posts: 117

Extract text from Illustrator file using shell script

Since Illustrator CC 2018, Adobe no longer writes the file version into the resource fork. Unfortunately, my scripting environment relies on reading this to record the information in our artwork slug.

I can't find a solution to this, but I have an idea… When I open the .ai file in TextEdit, I can see a line beginning with "%%Creator: Adobe Illustrator(R) " and then a number. That is 15.0 for CS 5, and 17.0 for CC.

I would like to extract the text from this line using a shell script, but my knowledge of this is more limited than Applescript! What I have here doesn't work:

Applescript:


set theFileVersion to do shell script "grep '%%Creator:' /Users/username/Desktop/test.ai | pbcopy "
log theFileVersion

Thanks in advance for any help


Filed under: grep, Illustrator, shell

Offline

 

#2 2019-04-08 02:46:46 am

divster
Member
Registered: 2011-03-01
Posts: 117

Re: Extract text from Illustrator file using shell script

Right!
I have found something that works, if anyone is interested

Applescript:


set search_command to "awk '/%%Creator/ { print $5 }' /Users/username/Desktop/test.ai "
set theFileVersion to do shell script search_command

This returns:
"17.0
%%AI8_CreatorVersion:"

The number is what I want, and I can use applescript to get rid of the trailing text.
…unless anyone knows how to do this with awk or another command line thingy.

For anyone wracking their brains to learn this stuff, I found the most useful info here:
https://www.lifewire.com/write-awk-comm … ts-2200573


Filed under: awk, Illustrator, shell

Offline

 

#3 2019-04-09 05:14:50 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 864

Re: Extract text from Illustrator file using shell script

My awk knowledge is also not particularly extensive; that said, I saw that your result anomalously occupies more than one line after accessing the fifth found item, so I played around with it. Your implementation appears to actually be ignoring the pattern after the first "%," and it just happens to be returning something approximating the desired result. The problem stems from unexpected line endings, and it can be corrected as below. Full disclosure... I also got some help from reading this post: https://stackoverflow.com/questions/445 … to-newline

#this respects the pattern

Applescript:

do shell script "awk 'BEGIN{ RS = \"\\r\" ; FS = \"\\n\" } /%%Creator: Adobe Illustrator[(]R[)] / {print $0}' " & (choose file)'s POSIX path's quoted form --->"%%Creator: Adobe Illustrator(R) 13.0"

--or:

#this alternate will isolate the number portion

Applescript:

do shell script "awk 'BEGIN{ RS = \"\\r\" ; FS = \"\\n\" } /%%Creator: Adobe Illustrator[(]R[) ]/ {print substr($0,33,4) }' " & (choose file)'s POSIX path's quoted form --->13.0

--Edit: $1 changed to $0; the former worked, but there is only one found item

Last edited by Marc Anthony (2019-04-09 07:20:36 pm)

Offline

 

#4 2019-04-11 04:21:19 pm

divster
Member
Registered: 2011-03-01
Posts: 117

Re: Extract text from Illustrator file using shell script

Thanks Marc

Your awk code worked a treat.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)