Rename using metadata from outlook msg files

This add-in establishes the basic functionality. It creates two commands to start and stop the monitoring: WatchOutlookMsgStart and WatchOutlookMsgStop.

You need to adjust the folder to be monitored and the commands to execute.


Save CommandWatchOutlookMsg.js.txt to   

%appdata%\GPSoftware\Directory Opus\Script AddIns

How to use buttons and scripts from this forum

JScript
function OnInit(initData) {
    initData.name = 'WatchOutlookMsg';
    initData.version = '2024-11-20';
    initData.url = 'https://resource.dopus.com/t/rename-using-metadata-from-outlook-msg-files/39930/27';
    initData.desc = 'WatchOutlookMsg';
    initData.default_enable = true;
    initData.min_version = '13.0';
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'WatchOutlookMsgStart';
    cmd.method = 'OnWatchOutlookMsgStart';
    cmd.desc = 'WatchOutlookMsgStart';
    cmd.label = 'WatchOutlookMsgStart';
    cmd.template = '';
    cmd.hide = false;
    cmd.icon = 'script';

    var cmd = addCmdData.AddCommand();
    cmd.name = 'WatchOutlookMsgStop';
    cmd.method = 'OnWatchOutlookMsgStop';
    cmd.desc = 'WatchOutlookMsgStop';
    cmd.label = 'WatchOutlookMsgStop';
    cmd.template = '';
    cmd.hide = false;
    cmd.icon = 'script';
}

var fsu = DOpus.FSUtil();
var itemID = 'RenameOutlookMsg';

function OnWatchOutlookMsgStart(scriptCmdData) {
    var item = fsu.GetItem(fsu.Resolve('D:\\MyOutlookMsgInboxFolder'));
    fsu.WatchChanges(itemID, item, 'f');  // monitor for file change in folder (e.g. file created)
    DOpus.Output('Started monitoring');
}

function OnWatchOutlookMsgStop(scriptCmdData) {
    fsu.CancelWatchChanges(itemID);
    DOpus.Output('Stopped monitoring');
}

function OnFilesystemChange(FilesystemChangeData) {
    if (FilesystemChangeData.id != itemID) return;

    // Note that you aren't told what changed, only that something meeting the specified conditions did change.

    DOpus.Output('Action!');

    var cmd = DOpus.Create().Command();

    var cmdLine = 'Rename PRESET=Email';
    DOpus.Output(cmdLine);
    // cmd.RunCommand(cmdLine);
}