Blog
The Franken-Scriptor Lives!
20/12/2006
Well after a fair bit of hacking and QA I've got the script engine in Scribe running some non-trivial scripts. In test11 you'll be able to create scripts and have them hang off the tools menu of the main window. Just put a ".script" file in "./Scripts" under Scribe.exe and it'll get inserted in the Tools menu. Inside the script you need to define a "Main" function in LGI script (see i.Mage's help for documentation) which will get run when you select the menu item that corrasponds to the script.

I'm initially converting the existing bottom 3 "utility" style commands on Tools menu to script to test the system. So far the first one looks like this:
//
// Deletes all the attachments in the current folder after asking the user.
//
// MenuText = Delete all attachments in current folder
// MenuStrRef = 1266
//
function Main(App)
{
    Folder = App.CurrentFolder;

    Print("Folder='" + Folder.Path + "'\n");

    if (Folder)
    {
        if (Folder.Type == 0xAAFF0001)
        {
            Load(Folder);

            Bytes = 0;
            Count = 0;
            Len = Folder.Length;
            
            for (i=0; i<Len; i++)
            {
                t = Folder.Item[i];
                if (t)
                {
                    Attachments = t.Attachments;
                    for (n=0; n<Attachments; n++)
                    {
                        a = t.Attachment[n];
                        if (a)
                        {
                            Bytes += a.Length;
                            Count++;
                        }
                    }
                }
            }

            if (MsgBox( App,
                        "Do you want to delete " + Bytes + " bytes in " + Count + " attachments?",
                        Name,
                        4) == 6)
            {
                for (i=0; i<Len; i++)
                {
                    t = Folder.Item[i];
                    if (t)
                    {
                        Attachments = t.Attachments;
                        for (n=0; n<Attachments; n++)
                        {
                            a = t.Attachment[n];
                            Delete(a);
                        }
                    }
                }
            }
        }
        else
        {
            MsgBox(App, "Folder doesn't contain mail.", "Delete Attachments");
        }
    }
    else
    {
        MsgBox(App, "No current folder?", "Delete Attachments");
    }
}


And that works fine. It's a little rough around the edges but it works as advertised. I had to fix a few things in the script engine and also add some more functions and fields in to the objects.

I hope to convert the other 2 tools into script before I release test11. Sometime after the release I'll document the language and commands here. As the old scripting plugin is deprecated, I may as well use that page from something useful.


Comments:

fret
21/12/2006 6:00am
Ok, so I didn't provide any default scripts in the Test11 build, but you can create your own "Scripts" subfolder and paste this script above into a text file calles "DeleteAttachments.script" and it'll show up in the Tools menu.
mhf
21/12/2006 11:31am
Yes, works fine. Looking forward to some more examples and am looking through the scripting API


From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]
Post