Skip to content

Instantly share code, notes, and snippets.

@sacrifs
Last active December 17, 2015 08:39
Show Gist options
  • Save sacrifs/5581435 to your computer and use it in GitHub Desktop.
Save sacrifs/5581435 to your computer and use it in GitHub Desktop.
Photoshop用。レイヤー名とテキストレイヤーのテキストをファイルに書き出し
/**
* Export2Text.jsx
*/
var _layers = [];
main();
function main(){
CR = String.fromCharCode(13);
var filepath = File.saveDialog("ファイル名を入力してください");
if(!filepath){
alert("ファイル名がありません");
return;
}
var document = activeDocument;
var layers = document.layers;
getLayer(layers);
var num = _layers.length;
var output = "";
for(var i = 0; i < num; i++){
var layerName = _layers[i].name;
output += "= = = = = = = = = = =" + CR;
output += "layer : " + layerName + CR;
if(_layers[i].kind == LayerKind.TEXT){
txt = _layers[i].textItem.contents;
output += txt + CR;
}
}
fileSave(filepath, output, "utf-8");
alert("処理が完了しました");
}
function getLayer(layers){
var num = layers.length;
for(var i = 0; i < num; i++){
var layer = layers[i];
if(layer.typename == "LayerSet"){
getLayer(layer.layers);
}
_layers.push(layer);
}
}
function fileSave(filepath, data, encoding){
var file = new File(filepath);
file.open("w");
file.encoding = encoding;
file.write(data);
file.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment