sakai-memoru
11/15/2019 - 1:40 AM

Sakura Macro : open_powershell.jse

Sakura Macro : open_powershell.jse

  • Sakura Editor から、CUI Shell (Windows PowerShell.exe)をopenする。
  • Working Folderは、編集しているファイルのあるフォルダ。

(function(){

// 
// powershell で編集フォルダをworkdirectoryとして開く
function doProcess(expandParam){
  var target_ = Editor.ExpandParameter(expandParam);
  var objShell = new ActiveXObject("WScript.Shell");
  objShell.CurrentDirectory = target_;
  var cmd_statement = "powershell.exe -noprofile ";
  Editor.ExecCommand(cmd_statement, 0)
}

// -------------- entry point
if(typeof(Editor) !== 'undefined'){
  // $F : opened file's full path
  // $f : opened file's name
  // $e : opened file's folder path
  // $b : opened file's extention
  // $C : 選択中の場合、選択テキストの1行目のテキスト(改行コード除く)
  //      選択中でない場合、カーソル位置の単語
  doProcess('$e');
  
} else {
  if(typeof(WScript) !== 'undefined'){
    WScript.Echo('[Warn] This script is for sakura macro. A env is maybe wsh.')
  } else {
    console.log('[Warn] This script is for sakura macro. A env is maybe node.')
  }
}

}())