PDF-ShellTools > General

Attachments names in a metadata field

(1/1)

Pavel:
I very like PDF–ShellTools. It is best affordable program for working with Attachments. – But here I need help – please, tell me how can I automatically load the names of Attachments (from the Attachments list) to the Details pane Items and InfoTip. Now I have created a Custom Field Attachments\Name: PDFCustom1\Type: Text and I´m manually writhing the names of Attachments to file(-s) via Properties\Details pane.

I have WIN 7 Ultimate 64-bit.

RTT:
I suppose a script, with the help of the ListAttachments and SetMetadata command line interface functions, could do the job.

Something like this:

--- Code: ---var WshShell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1,
    ForWriting = 2,
    ForAppending = 8;
var TristateUseDefault = -2,
    TristateTrue = -1,
    TristateFalse = 0;

function getPDFShellToolsPath() {
    var oEnv = WshShell.Environment("System");
    switch (oEnv("PROCESSOR_ARCHITECTURE").toLowerCase()) {
    case "amd64":
        return "\"%ProgramFiles(x86)%\\PDF-ShellTools\\PDFShellTools.exe\"";
    default:
        return "\"%ProgramFiles%\\PDF-ShellTools\\PDFShellTools.exe\"";
    }
}

function AttachmentsListToMetadataField(filename) {
    if (fso.GetExtensionName(filename) === 'pdf') {
        var FilePath = fso.GetParentFolderName(filename);
        var AttachmentsListFilename = FilePath + "\\Attachments.txt";
        if (fso.FileExists(AttachmentsListFilename)) {
            fso.DeleteFile(AttachmentsListFilename);
        }
        var ShellToolsPath = getPDFShellToolsPath();
        WshShell.Run(ShellToolsPath + " ListAttachments \"OutFilename=" + AttachmentsListFilename + "\" \"" + filename + "\"", 0, true);
        if (fso.FileExists(AttachmentsListFilename)) {
            var ts = fso.OpenTextFile(AttachmentsListFilename, ForReading, false, TristateFalse);

            var Attachments = new Array;
            while (!ts.AtEndOfStream) {
                Attachments.push(ts.ReadLine());
            }
            ts.Close();
            fso.DeleteFile(AttachmentsListFilename);
            WshShell.Run(ShellToolsPath + " SetMetadata -UTF8Encoded \"Metadata='Attachments=" + Attachments.join(';') + "'\" \"" + filename + "\"", 0, true);        }
    }
}

var objArgs = WScript.Arguments;
for (i=0; i<objArgs.length; i++){
AttachmentsListToMetadataField(objArgs(i));
}

--- End code ---
Save this code to an AttachmentsToMetadata.js file and put it in the SendTo folder (type shell:sendto in the Windows Explorer address bar to easily locate, and open, this folder).
Now you just need to select the PDF files, right click them, and choose the Shell context menu "send to>AttachmentsToMetadata.js" item, to get these PDF files attachments names saved to a PDF custom metadata field, named Attachments.

Navigation

[0] Message Index

Go to full version