ごんれのラボ

iOS、Android、Adobe系ソフトの自動化スクリプトのことを書き連ねています。

Illustratorファイルのバージョンを調べてみる

お仕事で他社からごちゃっとデータが入稿されたのだが、FTP経由なので「情報をみる」でバージョンがわからなくて、うにゃーーーーーーー!ってなったので書いてみた。

Rubyからgemのmini_exiftoolを使ってXMPのCreatorToolタグとCreatorタグを見てます。

どうして二つのタグを見てるかというとAIとEPSでXMPの内容が違うから。

いいです、もう慣れました。

バージョン判断後は戻り値から判断してファイルにラベルをつけています。

前々から気づいてたけどラベルをAppleScriptからつけると1番目のラベルは赤じゃなくてオレンジで、2番目が赤なんですよ。

で、今回気づいたのは4番目が緑じゃなくて青、5番目が青じゃなくて紫のようです。

細かいことですがちょっと焦った。

あ、ちなみにこのAppleScriptはexiftoolをインストール済、かつRubyGemsにしてないとmini_exiftoolを入れてないと動きません。

IllustratorPackageのように直接テキストとして解析してもよかったんだけど、バージョン判定なのでこっちのほうが確実かなーっと。

Ruby。

#! ruby -Ku

require 'CGI'

require 'kconv'

require 'rubygems'

require 'mini_exiftool'

def verionCheck(fileObj)

obj = MiniExiftool.new fileObj

key = obj['Creator']#古いIllustratorはこれで判断

if /Illustrator/ =~ key then

puts key

#break

else

#os9ver(ARGF)

puts "oldVer"

end

end

=begin #OS9は無視

def os9ver(fileObj)

lineALL = fileObj.gets

line_UTF8 = lineALL.kconv(Kconv::UTF8, Kconv::ASCII)

lineArray = line_UTF8.split("\r")

lineArray.each do | line |

if /%%Creator/ =~ line

if /Illustrator/ =~ line

str = "Illustrator"

puts str

end

end

end

=end

verionCheck(ARGV[0])

AppleScript。

on open theFiles

set my_script_name to "IllustratorVersionChecker.rb" as Unicode text --スクリプトファイル名

tell application "Finder"

activate

--ruby versionのチェック

set ruby_version to do shell script "ruby -e 'print \"ERROR\" if RUBY_VERSION <= \"1.8.1\"'"

if ruby_version is "ERROR" then

display dialog "このスクリプトはRubyバージョンが1.8.2以上で動作します"

error number -128

end if

--スクリプトバンドル内のスクリプトのパスを得る

set my_script_folder to parent of (path to me) as Unicode text

set my_script to my_script_folder & my_script_name

set my_script to (quoted form of POSIX path of my_script)

repeat with i in theFiles

set input_file to (quoted form of POSIX path of contents of i) as Unicode text

try

set checkResult to do shell script "source ~/.bash_profile;ruby " & my_script & " " & input_file

--display dialog checkResult

my labelFill(i, checkResult)

end try

end repeat

end tell

activate

display dialog "終了"

end open

to labelFill(i, checkResult)

tell application "Finder"

if "12" is in checkResult or "CS2" is in checkResult then

set label index of i to 1 --ラベルを付ける

else if "13" is in checkResult or "CS3" is in checkResult then

set label index of i to 2 --ラベルを付ける

else if "14" is in checkResult or "CS4" is in checkResult then

set label index of i to 3 --ラベルを付ける

else if "15" is in checkResult or "CS5" is in checkResult then

set label index of i to 4 --ラベルを付ける

else if "16" is in checkResult or "CS6" is in checkResult then

set label index of i to 5 --ラベルを付ける

else

display dialog "判定できませんでした"

end if

end tell

end labelFill

ダウンロードは後日。