Skip to content

Instantly share code, notes, and snippets.

@monokano
Last active December 13, 2022 13:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokano/31876b3f96e0c92e8a61fdc540d69dc9 to your computer and use it in GitHub Desktop.
Save monokano/31876b3f96e0c92e8a61fdc540d69dc9 to your computer and use it in GitHub Desktop.
InDesignファイル(ドキュメント、ブック、ライブラリ、テンプレート)の作成アプリバージョンを検出する
#!/usr/bin/python
#
# Usage: python inddver.py indesign-file(indd,indb,indl,indt)
#
# This script will detect the app version written in the indesign file.
#
import sys, os, re
def getAppName(verDec):
# get InDesign app name
fv = float(verDec)
mv = int(fv)
if mv >= 1 and mv <= 2:
return verDec
elif mv==3:
return 'CS'
elif fv >= 4 and fv < 7.5:
return 'CS' + str(mv - 2)
elif fv==7.5:
return 'CS5.5'
elif mv==8:
return 'CS6'
elif mv==9:
return 'CC'
elif mv >= 10 and mv <= 11:
return 'CC ' + str(mv + 2004)
elif mv >= 12 and mv <= 14:
return 'CC ' + str(mv + 2005)
else:
return str(2005 + mv)
if len(sys.argv) > 1 :
arg = sys.argv[1]
ex = os.path.splitext(arg)[1]
if ex in {'.indd', '.indb', '.indl', '.indt'}:
f = open(arg, 'rb')
hexStr = f.read(48).encode('hex')
verHex = ''
if ex==".indd" or ex==".indt": #DOCUMENT
# new pattern
if ('444f43554d454e5401700f0' in hexStr):
verHex = re.sub(r'.+444f43554d454e5401700f0000(..)000000(..).*', r'\1.\2', hexStr)
# old pattern
elif ('444f43554d454e540200000f7' in hexStr):
verHex = re.sub(r'.+444f43554d454e540200000f70000000(..)000000(..).*', r'\1.\2', hexStr)
elif ex==".indb": #BOOKBOOK
# new pattern
if ('424f4f4b424f4f4b01700f0' in hexStr):
verHex = re.sub(r'.+424f4f4b01700f0000(..)000000(..).*', r'\1.\2', hexStr)
# old pattern
elif ('424f4f4b424f4f4b0200000f7' in hexStr):
verHex = re.sub(r'.+424f4f4b424f4f4b0200000f70000000(..)000000(..).*', r'\1.\2', hexStr)
elif ex==".indl":
# new pattern #LIBRARY4
if ('4c4942524152593401700f0' in hexStr):
verHex = re.sub(r'.+4c4942524152593401700f0000(..)000000(..).*', r'\1.\2', hexStr)
# old pattern #LIBRARY2 or LIBRARY4
elif ('4c494252415259' in hexStr):
verHex = re.sub(r'.+4c494252415259..0200000f70000000(..)000000(..).*', r'\1.\2', hexStr)
if verHex:
# hex to dec
majorDec = int(verHex[:2],base=16)
minorDec = int(verHex[3:5],base=16)
verDec = str(majorDec) + '.' + str(minorDec)
# return value
print 'Adobe InDesign ' + getAppName(verDec) + ' (v' + verDec + ')'
else :
print >> sys.stderr, 'Usage: python inddver.py indesign-file(indd,indb,indl,indt)'
sys.exit()
else :
print >> sys.stderr, 'Usage: python inddver.py indesign-file(indd,indb,indl,indt)'
sys.exit(2)
@monokano
Copy link
Author

Python3用→ inddver3.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment