書庫ファイル内の画像ファイルをサムネイルにする。
準備
以下の二つのファイルをScriptフォルダに保存。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//!*script | |
// 書庫ファイルから画像を抽出する | |
// 7zipが必要 | |
// 第一引数:書庫ファイルのパス | |
// | |
// 例:*setentryimage %*script(%0Script\getarchiveimage.js,%FCD) -save | |
// 引数がなければ終了 | |
if (PPx.Arguments.Length < 1){ | |
PPx.SetPopLineMessage("引数が正しくありません。"); | |
PPx.Quit(); | |
} | |
// 7z.exeのパス | |
//var exec = "C:\\Program Files\\7-Zip\\7z.exe"; | |
const exec = PPx.Extract('%\'7z\''); | |
const tempdir = PPx.Extract("%*temp(name,d)"); | |
const sorce_file = PPx.Arguments(0); | |
const fso = PPx.CreateObject("Scripting.FileSystemObject"); | |
const allowExtensions = /\.(jpg|jpeg|png|gif)$/i; // 拡張子の指定 | |
// 7zipで一時フォルダに解凍 | |
const command = '%OBnsq ' + exec + '' + ' e -y ' + ' -o\"' + tempdir + '\" \"' + sorce_file + '\"'; | |
PPx.Execute(command); | |
// ファイルパスを取得 | |
const objFolder = fso.GetFolder(tempdir); | |
const enmFile = PPx.Enumerator(objFolder.Files); | |
for (; !enmFile.atEnd(); enmFile.moveNext()){ | |
f_name = enmFile.item().Name.toUpperCase(); | |
if (f_name.match(allowExtensions)){ | |
const cover_path = PPx.Extract('%*name(BCD,"'+f_name+'","'+tempdir+'")'); | |
PPx.Result = cover_path; | |
break; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//!*script | |
// | |
// 書庫ファイルの表紙画像をサムネイルにする | |
// カレントフォルダのマークファイルかつ書庫ファイルに対して実行 | |
// このスクリプトと同じフォルダにgetarchiveimage.jsを置く必要 | |
// e.g. *script %0Script\setarchiveimage_marked.js | |
const script_dir = PPx.Extract('%*name(KD,"' + PPx.ScriptName + '")'); | |
const allowExtensions = /\.(zip|rar)$/i; // 拡張子の指定 | |
// マークがない場合の処理 | |
if (!PPx.EntryMarkCount) { | |
const filepath = PPx.Extract('%1') + "\\" + PPx.EntryName; | |
if (PPx.EntryName.match(allowExtensions)&& !(PPx.EntryAttributes & 16)){ | |
const img = PPx.Extract('%*script('+script_dir+'\\getarchiveimage.js,"'+filepath+'")'); | |
PPx.Execute("*setentryimage "+img+" -save"); | |
} | |
} else { | |
// マークがある場合の処理 | |
PPx.EntryFirstMark; | |
while(true){ | |
const filepath = PPx.Extract('%1') + "\\" + PPx.EntryName; | |
if (PPx.EntryName.match(allowExtensions)&&!(PPx.EntryAttributes & 16)){ | |
const img = PPx.Extract('%*script('+script_dir+'\\getarchiveimage.js,"'+filepath+'")'); | |
PPx.Execute("*setentryimage "+img+" -save"); | |
} | |
if(PPx.EntryNextMark != 1) break; | |
} | |
} |
やり方
エントリ表示形式を、画像が含まれるものに変更する。とりあえずは、[;]で表示されるメニューから「サムネイル1」を選んでおけばいい。こうしないと、以下の過程で「no image mode」と言われてしまう。
カーソル下の書庫ファイルのサムネイルを変更したい場合は、以下のコマンドを実行する。
*setentryimage %*script(%0Script\getarchiveimage.js,%FCD) -save
複数の書庫ファイルのサムネイルを同時に変更したい場合は、ファイルをマークした後、以下のコマンドを実行する。
*script %0Script\setarchiveimage_marked.js
0 件のコメント:
コメントを投稿