é¸æããæååãç´¢å¼é ç®ã«ç»é²ããJavaScriptï¼èªã¿ä»®åèªåå ¥åãCS3ãï¼
ã¯ãããã°ãã¯ã
InDesignã§ç´¢å¼é
ç®ã追å ããã¨ãã¯ã½ã¼ãã®ããã«èªã¿ä»®åãå
¥åããªãã¦ã¯ãªããªãã®ã§ãããææã¡ããã®ããã¾ãã«ãããã©ãããã®ã§èªåçã«åå¾ããã¹ã¯ãªãããä½ãã¾ããã
èªã¿ä»®åã®åå¾ã«ã¯ã¿ããªå¤§å¥½ãYahoo!のテキスト解析WebAPIãå©ç¨ãã¦ãã¾ãã
ããã¾ã§èªåç¨ã«ä½ã£ããã®ãªã®ã§ã
- åç §å½¢å¼ã¯ããã©ã«ãã®ãç¾å¨ã®ãã¼ã¸ãã®ã¿
- é ç®ã®ã¬ãã«ã¯è¨å®ã§ããªãï¼ãã¹ã¦ã¬ãã«1ã«ãªãï¼
ã¨ããä»æ§ã«ãªã£ã¦ãã¾ãã
ãã¨ãAPIã®ã¢ããªã±ã¼ã·ã§ã³IDã¯æ¶ãã¦ããã¾ãã®ã§ããã使ç¨ããå ´åã¯èªåã®ã¢ããªã±ã¼ã·ã§ã³IDï¼ã©ã³ãã ãªè±æ°åã«ãªã£ã¦ã¾ãï¼ãåå¾ãã¦ããâââã³ã³ã«ã¢ããªã±ã¼ã·ã§ã³IDãæ¸ãâââãã®ã¨ããã«å
¥ãã¦ãã ããï¼1ç®æã ãã§ãï¼ãYahooã®IDãä½ãã°èª°ã§ãåå¾ã§ãã¾ãã
ã¡ãã£ã¨è©¦ãã¦ã¿ããã¨ãã人ã«ã¯ã ãã¶ä¸è¦ªåã§ãããäºæ¿ãã ããï¼ï¼
ãã®ã¹ã¯ãªãããæ¸ãã«ããã£ã¦ã2ã¤ã®è¨äºã大ãã«åèã«ããã¦ããã ãã¦ãã¾ãã
- 表ãããã¨ãã¼ã«ã¼æ¿å ¥ä½ç½®ããããã¨ããæå³ããããªããã°ã®åé¿ï¼索引をスクリプトからなんとかして埋め込む
- InDesignããã®HTTPã¢ã¯ã»ã¹ï¼InDesignでSocketクラスの上位クラスを作りHTTPでアクセス
åä½ç¢ºèªã¯ãWinXP + CS4ãWinXP + CS5.5ãWin7 + CS5.5ãMacOSX 10.7.5 + CS3ãMacOSX 10.5.8 + CS3ãMacOSX 10.5.8 + CS4ã§è¡ãã¾ãããMacã§ã®åä½ç¢ºèªã«ãååããã ãããäºæ¹ããããã¨ããããã¾ããï¼ãé
ãã¦ããã¾ããï¼
â 使ç¨åã®ç¢ºèªäºé
- ãªã«ãèµ·ãã¦ãæ³£ããªãããã«ãã¼ã¿ã®ããã¯ã¢ãããåããªãã使ç¨ãã¦ãã ããï¼æéè¦ï¼ã
- ã¤ã³ã¿ã¼ãããã¸ã¢ã¯ã»ã¹ã§ããç°å¢ãå¿ è¦ã§ãã
- Yahoo!ã®ãæ¥æ¬èªå½¢æ ç´ è§£æAPIãã使ç¨ãã¦ãã¾ãããµã¼ãã¹ãçµäºããå ´åãã¹ã¯ãªããã使ç¨ã§ããªããªãã¾ãã
- é¸æä¸ã®æååãã¤ã³ã¿ã¼ãããçµç±ã§Yahoo!ã®ãµã¼ãã¹ã¸éä¿¡ãã¾ããæ©å¯æ å ±ãªã©ãæ¼æ´©ããå ´åã§ã責任ã¯æã¡ã¾ããã
- ã¢ã¯ã»ã¹ãã°ãªã©ãè¦ãã°ãã©ããªæååãéä¿¡ããã誰ã§ããããã¾ãã
- è¨å·é¡ã¯èªã¿ä»®åããåé¤ããã¾ãã
â 使ç¨ä¸ã®æ³¨æäºé
- APIãæå¾ éãã®èªã¿ä»®åãè¿ãã¦ããã¨ã¯éããªãã®ã§ãå¿ ã1件ãã¤ç¢ºèªããªããç»é²ãã¦ãã ããã
- ç»é²ç´å¾ã¯ç´¢å¼é ç®ã®ãã¼ã¸æ°ã表示ããã¾ãããç´¢å¼ããã«ã®ã¡ãã¥ã¼ããï¼»ãã¬ãã¥ã¼ãæ´æ°ï¼½ãå®è¡ããã¨ç´ãã¾ãã
- ç´¢å¼ç»é²æãããã¥ã¡ã³ãã®æåã®ãã¼ã¸ä»è¿ã«ããã¼ã®ããã¹ããã¬ã¼ã ãä½ããã¾ããé常ã¯èªåçã«åé¤ããã¾ãããã¹ã¯ãªãããéä¸ã§æ¢ã¾ã£ãå ´åãªã©ã«æ®ãå¯è½æ§ãããã¾ããã²ã¨ã¨ããç»é²ãããããã¬ã¼ã ãæ®ã£ã¦ããªãã確èªãã¦ãã ããããã£ããæ¶ãã¦ãã
- ãªã«ãèµ·ãã¦ãæ³£ããªãããã«ãã¼ã¿ã®ããã¯ã¢ãããåããªãã使ç¨ãã¦ãã ããï¼å¿µæ¼ãï¼ã
// ç´¢å¼ç»é²æ¯æ´ãã¼ã«ï¼InDesign CS3ãï¼ // Yahoo!ã®ããã¹ã解æAPIãå©ç¨ãã¦ç´¢å¼ã®èªã¿ä»®åå ¥åãèªååãã¾ãã // http://developer.yahoo.co.jp/webapi/jlp/ // // 以ä¸ã®è¨äºããã¯^H^H大ãã«åèã«ããã¦ããã ãã¦ãã¾ãã // kmutoãã // via http://d.kmuto.jp/20120912.html // CLãã // via http://d.hatena.ne.jp/C_L/20081012/indesign_socket_http // // v0.9 2013/04/03 // v1.0 2013/06/03 ããã©ã«ãã¹ã¿ã¤ã«ã®åæåå¦ç追å ãèªåã§ä½¿ç¨éå§ // v1.1 2013/06/17 åæåå¦çãããã¦ããã¼æåã®ãµã¤ãºã ãæå®ããå½¢ã«å¤æ´ // // NYSL http://www.kmonos.net/nysl/ // ============================================================================== main(); // ã¡ã¤ã³ã®å¦ç function main(){ //Yahoo!APIã®ã¢ããªã±ã¼ã·ã§ã³ID var myAppID = "âââã³ã³ã«ã¢ããªã±ã¼ã·ã§ã³IDãæ¸ãâââ"; // é¸æç¶æ ãã§ãã¯ï¼ããã¹ããªãã¸ã§ã¯ããé¸æãã¦ãç¶æ ã®ã¿åä½ï¼ if(app.selection.length == 0 || !app.selection[0].constructor.name.match(/^(Text|Word|Character|Paragraph|Line|TextColumn|TextStyleRange)$/)){ alert("ç´¢å¼ç»é²å¯è½ãªããã¹ããé¸æãã¦ãã ããã"); return false; } var actDoc = app.activeDocument; var idx = (actDoc.indexes.length > 0) ? actDoc.indexes[0] : actDoc.indexes.add(); var targ = app.selection[0]; // é¸æä¸ã®ããã¹ã var title = targ.contents; // ç´¢å¼é ç®ã«ãªãæè¨ // APIãªã¯ã¨ã¹ã var yapiObj = new YAPIReading(); yapiObj.appid = myAppID; var reading = yapiObj.getReading(title); // èªã¿ããªã«ãªãæè¨ // 表示ãã¤ã¢ãã°æºå // ãã¤ã¢ãã°ã§èªã¿ããªãä¿®æ£å¯è½ var dlg = createDialog(); dlg.tf.text = title; // ç´¢å¼é ç®æ¬ã«å ¥å dlg.rf.text = reading; // èªã¿ããªæ¬ã«å ¥å // èªã¿ããªã空æåï¼APIãã¨ã©ã¼è¿ãã¦ãã¦ãï¼ã ã£ããã¡ãã»ã¼ã¸ãä¸æ¸ããã if(reading == ""){ dlg.info.text = "èªã¿ããªã®èªååå¾ã«å¤±æãã¾ãããç´æ¥å ¥åãã¦ãã ããã"; } // ãã¤ã¢ãã°è¡¨ç¤ºããç»é²å®è¡ // ç»é²ãã¿ã³ãæ¼ãã¨ããã®æç¹ã®èªã¿ããªæ¬ã®ããã¹ããèªã¿ããªã¨ãã¦ç»é² if(dlg.show() == 1){ title = dlg.tf.text; reading = dlg.rf.text; try{ embedIndex(idx, targ, title, reading); // ç»é²å®è¡ } catch(e) { alert("ç»é²ã«å¤±æãã¾ããã\nç´¢å¼é ç®ã¾ãã¯èªã¿ããªã«ä½¿ããªãæåããªãã確èªãã¦ãã ããã"); arguments.callee(); } return true; } return false; // ç»é²ããªãã£ããfalseè¿ããã¨ã«ãã¦ããï¼ãªãã¨ãªãï¼ } // *************************************************************************** // // 以ä¸ãé¢æ°ã»ãªãã¸ã§ã¯ãå®ç¾©ãªã© // // *************************************************************************** // ç´¢å¼ã追å ããé¢æ° ******************************************************** // kmutoããã®ã¢ã¤ãã£ã¢ï¼ãã¼ã«ã¼ã®ã³ããï¼ãæå // via http://d.kmuto.jp/20120912.html // *************************************************************************** function embedIndex(index, target, title, reading) { // ããã¼ã®ããã¹ããã¬ã¼ã ãä½ã£ã¦â ãã¼ã¯ã¨ãå ¥ãã¦ãã var dummyFrame = index.parent.pages[0].textFrames.add(); dummyFrame.geometricBounds = [0, 0, 50, 50]; // ãµã¤ãºã¯é©å½ dummyFrame.insertionPoints[0].pointSize = 1; // æåããµã対çã«ãµã¤ãºãå°ãããã¦ãã dummyFrame.contents = "â "; // é ç®è¿½å // ããã¼ã®â ãã¼ã¯ã®ã¨ããã«ç´¢å¼ãã¼ã«ã¼ãå ¥ãã index.topics.add(title, reading).pageReferences.add(dummyFrame.characters[0]); // ãã¼ã«ã¼æåãã«ããï¼ãã¼ã¹ããã¦æ£ããä½ç½®ã«ç§»å dummyFrame.characters[0].select(); app.cut(); target.insertionPoints[0].select(); app.pasteWithoutFormatting(); // ãã©ã¼ããããªãã§ãã¼ã¹ã // ããã¼ã®ãã¬ã¼ã ãå§æ« dummyFrame.remove(); } // ãã¤ã¢ãã°ãªãã¸ã§ã¯ããä½ã£ã¦è¿ãé¢æ° ************************************ // ãã¨ã§é¨åã«ã¢ã¯ã»ã¹ããããããã«ã·ã§ã¼ãã«ããä½ã£ã¦ãã // dlg.tf : é ç®å ¥åæ¬ // dlg.rf : èªã¿ããªå ¥åæ¬ // dlg.info : æ å ±æ¬ // *************************************************************************** function createDialog(){ var dlg = new Window("dialog", "ç´¢å¼ç»é²"); dlg.orientation = "row"; dlg.alignChildren = "top"; var inputG = dlg.add("group"); inputG.orientation = "column"; inputG.alignChildren = "left"; var infoLabel = inputG.add("statictext", undefined, "èªã¿ããªãä¿®æ£ãã¦ãã ããããã£ã³ã»ã«ããã¨ç»é²ãä¸æ¢ãã¾ãã"); var inputTitle = inputG.add("group"); inputTitle.orientation = "row"; var titleLabel = inputTitle.add("statictext", undefined, "ç´¢å¼é ç®ï¼"); var titleField = inputTitle.add ("statictext", undefined, undefined); titleLabel.characters = 9; titleField.characters = 35; var inputReading = inputG.add("group"); inputReading.orientation = "row"; var readingLabel = inputReading.add("statictext", undefined, "èªã¿ããªï¼"); var readingField = inputReading.add ("edittext", undefined, undefined); readingLabel.characters = 9; readingField.characters = 35; var buttonG = dlg.add("group"); buttonG.orientation = "column"; buttonG.add("button", undefined, "ç»é²", {name: "ok"}); buttonG.add("button", undefined, "ãã£ã³ã»ã«", {name: "cancel"}); // ã·ã§ã¼ãã«ããå®ç¾© dlg.tf = titleField; dlg.rf = readingField; dlg.info = infoLabel; return dlg; } // èªã¿ããªåå¾ç¨ã¯ã©ã¹å®ç¾© ************************************************** // ã¢ããªã±ã¼ã·ã§ã³IDã¯ã¤ã³ã¹ã¿ã³ã¹å´ã§è¨å®ãã // // var hoge = new YAPIReading(); // ã¤ã³ã¹ã¿ã³ã¹ä½æ // hoge.appid = "â â ã¢ããªã±ã¼ã·ã§ã³IDâ â "; // èªåã®ã¢ããªã±ã¼ã·ã§ã³IDãæå®ãã // var title = "åã®å¦¹ã¯æ¼¢åãèªãã"; // èªã¿ããæè¨ // var reading = hoge.getReading(title); // 解æçµæãåå¾ // // ã£ã¦ãã // è¨å·é¡ã¯filterã§é¤å»ããããå¤æ´å¯è½ // èªã¿ããªé¨åã®æ½åºã¯ããã¹ããã®ã¾ã¾æ£è¦è¡¨ç¾ã§ã¶ã£ãã¬ããXML解æãªã«ããããããã® // *************************************************************************** function YAPIReading(){ this.appid = ""; this.filter = "1|2|3|4|5|6|7|8|9|10|11|12"; this.response = "reading"; this.results = "ma"; this.rex = /<reading>(.*?)<\/reading>/g; // <reading>è¦ç´ ãè¦ã¤ããæ£è¦è¡¨ç¾ï¼gãªãã·ã§ã³ä»ãï¼ this.getReading = function(sentence){ var reading = ""; var requestURI = 'http://jlp.yahooapis.jp/MAService/V1/parse?' + 'appid=' + this.appid + '&ma_filter=' + this.filter + '&response=' + this.response + '&results=' + this.results + '&sentence=' + encodeURI(sentence); var lwp = new Lwp(); var result = lwp.get(requestURI); // gãªãã·ã§ã³ä»ãRegExpãªãã¸ã§ã¯ãã®execã«ã¼ã // <reading>è¦ç´ ãè¦ã¤ãããã³ã«ä¸èº«ã®ããã¹ãã足ãã¦ãã var m; while (m = this.rex.exec(result)) { reading += m[1]; } return reading; // ãªã¯ã¨ã¹ãã«å¤±æããå ´åã¯readingã¿ã°ããªãã®ã§ç©ºæåã«ãªã£ã¦ãã¯ã } return this; } // HTTPã¢ã¯ã»ã¹ï¼GETï¼ç¨ã¯ã©ã¹å®ç¾© ******************************************* // CLããã®ã¢ã¸ã¥ã¼ã«ãå¾®æ¹é // via http://d.hatena.ne.jp/C_L/20081012/indesign_socket_http // prototypeãããã¦User-Agentãããã£ã½ãããã ã // *************************************************************************** function Lwp() { this.userAgent = "InDesign/" + app.version + " (InDesign " + app.version + "; " + $.os + "; ja)"; this.uri = function(uri) { var rex = new RegExp('http://([^:/]+)(?::(\d+))?(.+)'); // via http://pc11.2ch.net/test/read.cgi/php/1015692614/57 var urlObj =[]; if ( uri.match(rex) ) { urlObj.host = RegExp.$1; urlObj.port = RegExp.$2 ?RegExp.$2 :80; urlObj.path = RegExp.$3; } return urlObj; } this.get = function (uri) { var conn = new Socket; var urlObj = this.uri(uri); if ( conn.open(urlObj.host + ':' + urlObj.port, 'UTF-8') ) { conn.write ("GET " + urlObj.path + " HTTP/1.0\n" + "Host: " + urlObj.host + "\n" + "User-Agent: " + this.userAgent + "\n\n"); var reply = conn.read(999999); conn.close(); return reply.substring(reply.indexOf("\n\n") + 2); } } return this; };