Upgrade to Pro — share decks privately, control downloads, hide ads and more …

小さな面倒を解消するjsx群(+そのプラグイン化について) - Photoshop and me

小さな面倒を解消するjsx群(+そのプラグイン化について) - Photoshop and me

スライドのURLリンク一覧です。
「moremorefor/PhotoshopTinyPatch」 https://github.com/moremorefor/PhotoshopTinyPatch
「Adobe-CEP/CEP-Resources」 https://github.com/Adobe-CEP/CEP-Resources
「Creative Cloud Extension Builder for Brackets」 http://davidderaedt.github.io/CC-Extension-Builder-for-Brackets/
「davidderaedt/CC-EXT-SDK」 https://github.com/davidderaedt/CC-EXT-SDK
「moremorefor/PhotoshopSampleExt」 https://github.com/moremorefor/PhotoshopSampleExt

more_more_for

June 24, 2014
Tweet

Other Decks in Programming

Transcript

  1. /*    *  ApplyTextToLayerName.jsx    *    *  Copyright  (c)

     more_more_for.    *    *  This  software  is  released  under  the  MIT  License.    *  http://opensource.org/licenses/mit-­‐license.php    *    */       preferences.rulerUnits  =  Units.PIXELS;       var  openDoc  =  activeDocument;       main();       function  main()  {          openDoc.suspendHistory('ApplyTextToLayerName','ApplyTextToLayerName(openDoc)');   }           function  ApplyTextToLayerName(doc)  {      var  arr  =  getSelectedLayersIdx();      for(var  i=0;  i<arr.length;  i++)  {          var  idx  =  arr[i];          getLayerFromIndex(idx);              doc.activeLayer.name  =  doc.activeLayer.textItem.contents;      }   }       //////////////////////////////////////////////////   //  Select  layers  from  index   //////////////////////////////////////////////////   function  getLayerFromIndex(index)  {      var  idslct  =  charIDToTypeID(  "slct"  );          var  desc6  =  new  ActionDescriptor();          var  idnull  =  charIDToTypeID(  "null"  );                  var  ref4  =  new  ActionReference();                  var  idLyr  =  charIDToTypeID(  "Lyr  "  );                  ref4.putIndex(  idLyr,  index  );          desc6.putReference(  idnull,  ref4  );          var  idMkVs  =  charIDToTypeID(  "MkVs"  );          desc6.putBoolean(  idMkVs,  false  );   executeAction(  idslct,  desc6,  DialogModes.NO  );   }       function  getLayerReference(index)  {      var  idTrnf  =  charIDToTypeID(  "Trnf"  );                  var  desc48  =  new  ActionDescriptor();                  var  idnull  =  charIDToTypeID(  "null"  );                          var  ref36  =  new  ActionReference();                          var  idLyr  =  charIDToTypeID(  "Lyr  "  );                          var  idOrdn  =  charIDToTypeID(  "Ordn"  );                          var  idTrgt  =  charIDToTypeID(  "Trgt"  );                          ref36.putEnumerated(  idLyr,  idOrdn,  idTrgt  );                  desc48.putReference(  idnull,  ref36  );   }       };   ! function  getSelectedLayersIdx(){              var  selectedLayers  =  new  Array;              var  ref  =  new  ActionReference();              ref.putEnumerated(  charIDToTypeID("Dcmn"),  charIDToTypeID("Ordn"),  charIDToTypeID("Trgt")  );              var  desc  =  executeActionGet(ref);              if(  desc.hasKey(  stringIDToTypeID(  'targetLayers'  )  )  ){                    desc  =  desc.getList(  stringIDToTypeID(  'targetLayers'  ));                      var  c  =  desc.count                      var  selectedLayers  =  new  Array();                      for(var  i=0;i<c;i++){                          try{                                activeDocument.backgroundLayer;                                selectedLayers.push(    desc.getReference(  i  ).getIndex()  );                          }catch(e){                                selectedLayers.push(    desc.getReference(  i  ).getIndex()+1  );                          }                      }                }else{                    var  ref  =  new  ActionReference();                    ref.putProperty(  charIDToTypeID("Prpr")  ,  charIDToTypeID(  "ItmI"  ));                    ref.putEnumerated(  charIDToTypeID("Lyr  "),  charIDToTypeID("Ordn"),  charIDToTypeID("Trgt")  );                    try{                          activeDocument.backgroundLayer;                          selectedLayers.push(  executeActionGet(ref).getInteger(charIDToTypeID(  "ItmI"  ))-­‐1);                    }catch(e){                          selectedLayers.push(  executeActionGet(ref).getInteger(charIDToTypeID(  "ItmI"  )));                    }            var  vis  =  app.activeDocument.activeLayer.visible;                  if(vis  ==  true)  app.activeDocument.activeLayer.visible  =  false;                  var  desc9  =  new  ActionDescriptor();          var  list9  =  new  ActionList();          var  ref9  =  new  ActionReference();          ref9.putEnumerated(  charIDToTypeID('Lyr  '),  charIDToTypeID('Ordn'),  charIDToTypeID('Trgt')  );          list9.putReference(  ref9  );          desc9.putList(  charIDToTypeID('null'),  list9  );          executeAction(  charIDToTypeID('Shw  '),  desc9,  DialogModes.NO  );          if(app.activeDocument.activeLayer.visible  ==  false)  selectedLayers.shift();                  app.activeDocument.activeLayer.visible  =  vis;              }              return  selectedLayers;   100 lines
  2. ࣮࣭ߦ͘Β͍ function  ApplyTextToLayerName(doc)  {      var  arr  =  getSelectedLayersIdx();

         for(var  i=0;  i<arr.length;  i++)  {          var  idx  =  arr[i];          getLayerFromIndex(idx);              doc.activeLayer.name  =  doc.activeLayer.textItem.contents;      }   } ຊ࣭తͳͷ͸ߦ
  3. /*     <javascriptresource>   <name>Move  Objects</name>   <category>web</category>  

    </javascriptresource>   */       /*    *  auther:  Tsukada  Takumi  (@more_more_for)    *  ver:  1.0.3    */            preferences.rulerUnits  =  Units.PIXELS;       var  d  =  activeDocument;   d.suspendHistory("Move  Objects",  "main()");       function  handle_key  (event)  {      //Check  keyName      //alert(event.keyName);      var  step;      ScriptUI.environment.keyboardState['shiftKey']  ?  step  =  10  :  step  =  1;      if(event.keyName  ==  'LeftBracket'){          this.text  =  Number(this.text)-­‐step;          event.preventDefault();      }      if(event.keyName  ==  'RightBracket'){          this.text  =  Number(this.text)+step;          event.preventDefault();      }   }       function  createDialog()  {          var  wMargin  =  20;      var  hMargin  =  10;      var  wWidth  =  340;      var  wHeight  =  240;      var  characterHeight  =  20;      var  previousObj;      w  =  new  Window("dialog","Move  Objects",[100,100,100+wWidth,100+wHeight]);          var  textObjectX  =  new  Object();      textObjectX.left  =  wMargin;      textObjectX.top  =  hMargin*2;      textObjectX.right  =  wWidth  -­‐  150  -­‐  wMargin;      textObjectX.bottom  =  textObjectX.top  +  characterHeight;      w.labelX  =  w.add("statictext",  textObjectX,  "moveX:");          var  editObjectX  =  new  Object();      editObjectX.left  =  wMargin  +  150;      editObjectX.top  =  hMargin*2;      editObjectX.right  =  wWidth  -­‐  wMargin;      editObjectX.bottom  =  editObjectX.top  +  characterHeight;      w.movingX  =  w.add("edittext",  editObjectX);      previousObj  =  editObjectX;          var  textObjectY  =  new  Object();      textObjectY.left  =  wMargin;      textObjectY.top  =  previousObj.bottom  +  hMargin*2;      textObjectY.right  =  wWidth  -­‐  150  -­‐  wMargin;      textObjectY.bottom  =  textObjectY.top  +  characterHeight;      w.labelY  =  w.add("statictext",  textObjectY,  "moveY:");          var  editObjectY  =  new  Object();      editObjectY.left  =  wMargin  +  150;      editObjectY.top  =  previousObj.bottom  +  hMargin*2;      editObjectY.right  =  wWidth  -­‐  wMargin;      editObjectY.bottom  =  editObjectY.top  +  characterHeight;      w.movingY  =  w.add("edittext",  editObjectY);      previousObj  =  editObjectY;          var  checkboxObj  =  new  Object();      checkboxObj.left  =  wMargin;      checkboxObj.top  =  previousObj.bottom  +  hMargin*2;      checkboxObj.right  =  wWidth  -­‐  wMargin;      checkboxObj.bottom  =  checkboxObj.top  +  characterHeight;      w.duplicate  =  w.add("checkbox",  checkboxObj,  "Duplicate");      previousObj  =  checkboxObj;     !    var  cancelButtonObj  =  new  Object();      cancelButtonObj.left  =  wMargin;      cancelButtonObj.top  =  previousObj.bottom  +  hMargin*2;      cancelButtonObj.right  =  wWidth  -­‐  160  -­‐  wMargin;      cancelButtonObj.bottom  =  cancelButtonObj.top  +  characterHeight*2;      w.cancelButton  =  w.add("button",  cancelButtonObj,  "cancel");          var  okButtonObj  =  new  Object();      okButtonObj.left  =  wMargin  +  160;      okButtonObj.top  =  previousObj.bottom  +  hMargin*2;      okButtonObj.right  =  wWidth  -­‐  wMargin;      okButtonObj.bottom  =  okButtonObj.top  +  characterHeight*2;      w.okButton  =  w.add("button",  okButtonObj,  "OK");      previousObj  =  okButtonObj;          w.movingX.addEventListener  ("keydown",  handle_key  );      w.movingY.addEventListener  ("keydown",    handle_key  );          w.movingX.text  =  0;      w.movingY.text  =  0;      w.movingX.active  =  true;      w.duplicate.value  =  true;      return  w;   }       function  initializeDialog(w)  {      w.okButton.onClick  =  function()  {              var  moveLayer  =  d.activeLayer;                  var  _x  =  w.movingX.text  *  1.0;              var  _y  =  w.movingY.text  *  1.0;                  var  xx;              var  yy;              if(_x  ==  null){                  xx  =  0;              }else  {                  xx  =  _x;              }                  if  (_y  ==  null)  {                  yy  =  0;              }else  {                  yy  =  _y;              }                  var  duplicateOption  =  w.duplicate.value;                  if(duplicateOption)  {                  _moveLayer  =  moveLayer;                  var  duplicateLayer  =  moveLayer.duplicate();                  duplicateLayer.translate(xx,yy);                  }  else  {                  moveLayer.translate(xx,yy);              }                  w.close();      }   }       function  runDialog(w)  {          return  w.show();   };         function  main()  {      var  win  =  createDialog();          initializeDialog(win);          runDialog(win);   }   151 lines
  4. jsx