function getClipboardText() { var text; var clipboardDescriptor = new ActionDescriptor(); var textDescriptor = new ActionDescriptor(); var textKey = app.charIDToTypeID('TxtD'); clipboardDescriptor.putEnumerated(app.charIDToTypeID('GtDc'), app.charIDToTypeID('GtDc'), app.charIDToTypeID('TxBx')); var hasClipboardText = executeActionGet(clipboardDescriptor).hasKey(textKey);
if (hasClipboardText) { text = executeActionGet(clipboardDescriptor).getString(textKey); } else { text = ""; }
return text; }
// クリップボードからテキストを取得 var clipboardText = getClipboardText(); var activeDocument = app.activeDocument; var selectedLayer = activeDocument.activeLayer;
if (selectedLayer.kind == LayerKind.TEXT) { // テキストレイヤーのテキストをクリップボードのテキストに変更 selectedLayer.textItem.contents = clipboardText; // 画像を保存 var savePath = ""; // 保存先のパスを指定 if (savePath != "") { // 保存名はクリップボードから取得したテキスト+「さん」にする var fileName = clipboardText + "さん"; // 画像を保存 var saveFile = new File(savePath + "/" + fileName + ".jpg"); // 保存形式に合わせて拡張子を変更する var jpegOptions = new JPEGSaveOptions(); jpegOptions.quality = 10; // 画質設定(1〜12) activeDocument.saveAs(saveFile, jpegOptions, true, Extension.LOWERCASE); alert("画像を保存しました。"); } else { alert("保存先のパスが指定されていません。"); } } else { alert("選択しているレイヤーはテキストレイヤーではありません。"); }