Created
June 23, 2011 14:37
-
-
Save moluapple/1042655 to your computer and use it in GitHub Desktop.
Open Indd file with Creator app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************************** | |
* 作为bridge启动脚本使用 | |
* 选中Indd文件右键菜单调用 | |
* 可检测CS2-CS5.5版本Indd文件 | |
* 若系统安装了相应版本程序,则用其打开 | |
* 否则用最新版程序打开 | |
***********************************/ | |
#target bridge | |
var appInstalled = { | |
'4': BridgeTalk.isInstalled('indesign-4.0'), | |
'5': BridgeTalk.isInstalled('indesign-5.0'), | |
'6': BridgeTalk.isInstalled('indesign-6.0'), | |
'7': BridgeTalk.isInstalled('indesign-7.0'), | |
'7.5': BridgeTalk.isInstalled('indesign-7.5') | |
} | |
function getFileVersion(f) { | |
var IDVersion, Endianness; | |
f.open('r'); | |
f.seek(24, 0); | |
Endianness = f.readch().charCodeAt(0); | |
Endianness == 1 ? f.seek(29, 0) : f.seek(32, 0); | |
IDversion = f.readch().charCodeAt(0); | |
if (IDversion == 7) { | |
Endianness == 1 ? f.seek(33, 0) : f.seek(36, 0); //?? | |
IDversion += ('.' + f.readch().charCodeAt(0)); | |
} | |
f.close(); | |
return IDversion; | |
} | |
function btOpenFile(appVersion, file) { | |
BridgeTalk.bringToFront(appVersion); | |
var btMsg = new BridgeTalk(); | |
btMsg.target = appVersion; | |
btMsg.body = 'app.open(new File("' + file + '"))'; | |
btMsg.send(); | |
} | |
function openInIDByVer() { | |
this.requiredContext = "\tAdobe Bridge must be running.\n\tExecute against Bridge CS5 as the Target.\n"; | |
//$.level = 1; | |
this.menuID = "openInID"; | |
} | |
openInIDByVer.prototype.run = function () { | |
var retval = true; | |
if (!this.canRun()) { | |
retval = false; | |
return retval; | |
} | |
var cntCommand = new MenuElement("command", "用创建版本打开", "at the end of Thumbnail", this.menuID); | |
cntCommand.onSelect = function (m) { | |
var thumb = app.document.selections[0]; | |
var ver = getFileVersion(new File(thumb.path)); | |
switch (ver) { | |
case 4: | |
target = appInstalled[ver] ? 'indesign-4.0' : 'indesign'; | |
return btOpenFile(target, thumb.path); | |
case 5: | |
target = appInstalled[ver] ? 'indesign-5.0' : 'indesign'; | |
return btOpenFile(target, thumb.path); | |
case 6: | |
target = appInstalled[ver] ? 'indesign-6.0' : 'indesign'; | |
return btOpenFile(target, thumb.path); | |
case '7.0': | |
target = appInstalled[ver] ? 'indesign-7.0' : 'indesign'; | |
return btOpenFile(target, thumb.path); | |
case '7.5': | |
target = appInstalled[ver] ? 'indesign-7.5' : 'indesign'; | |
return btOpenFile(target, thumb.path); | |
default: | |
return btOpenFile('indesign', thumb.path); | |
} | |
}; | |
return retval; | |
} | |
openInIDByVer.prototype.canRun = function () { | |
if (BridgeTalk.appName == "bridge") { | |
if (MenuElement.find(this.menuID)) { | |
$.writeln("ERROR:: Menu element from openInIDByVer already exists!\nRestart Bridge to run this snippet again."); | |
return false; | |
} | |
return true; | |
} | |
$.writeln("ERROR:: Cannot run openInIDByVer"); | |
$.writeln(this.requiredContext); | |
return false; | |
} | |
new openInIDByVer().run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment