環境
- Windows 8.1 Pro
- Adobe Photoshop CS6
目標
出力時にactiveDocumentのディレクトリの中にoutputディレクトを作り、そこがデフォルトの出力先になるようにするコードを追加する。
追加対象は、例えば Export Layers To Files.jsx がある。
トラップ
何も考えないで次のコードを加えると
var outputDirPath = activeDocument.path + "/output";
パスに日本語を含むとき、dlgMain.etDestination.text
で当該部分が化ける(パーセントエンコーディング?)。
修正
ググると出てくるのはpath.fsName
を利用する方法である。
筆者はWindows/MacOSに両対応(?)させたかったので、パスを作った後Folderオブジェクトを作り、正しいパスを得る(fsName
)。
var outputDirPath = activeDocument.path + "/output";
var outputDir = Folder(outputDirPath);
var fsOutputDirPath = outputDir.fsName.toString();
dlgMain.etDestination.text = fsOutputDirPath;
//Check if it exist, if not create it.
if(!outputDir.exists) outputDir.create();
問題
Mac版でうまくいくかは未検証