Scripting

English main discussion
Post Reply
  • Author
  • Message
Offline
Posts: 8
Joined: Sun Nov 13, 2011 7:02 pm
Location: Dayton, Ohio, USA

Scripting

Post by Dellji »

Hello I am having trouble getting started with scripting in AKelpad. I have copied the following code from the Plugins Manual

var AkelPad=new ActiveXObject("AkelPad.document"); // create object
var WshShell=WScript.CreateObject("WScript.Shell"); // for popup
var hMainWnd=AkelPad.GetMainWnd(); // retrieve window handle var dummy if (hMainWnd) // if AkelPad window exists
dummy=WshShell.popup("AkelPad is running") else
dummy=WshShell.popup("AkelPad is NOT running")

Saved it in the c:\Akelpad\Akelfiles\Plugs\Scripts folder Executing it causes a "Automation server can't create object" error on line 1

What am I doing wrong?

Jim

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Dellji
Plugins manual is a little outdated.
About scripts, read this: ...\AkelPad\AkelFiles\Docs\Scripts-Eng.txt.

Your script might look like this:
var WshShell=new ActiveXObject("WScript.Shell"); // for popup
var hMainWnd=AkelPad.GetMainWnd(); // retrieve window handle
var dummy;
if (hMainWnd) //if AkelPad window exists
dummy=WshShell.popup("AkelPad is running");
else
dummy=WshShell.popup("AkelPad is NOT running");

No need to create AkelPad object. This is always available.

Offline
Posts: 8
Joined: Sun Nov 13, 2011 7:02 pm
Location: Dayton, Ohio, USA

Post by Dellji »

Thanks, That works much better.

Now if I can figure out how to do a save as and imbedded today's date in the file name I am all set to go.

Jim

Offline
Posts: 8
Joined: Sun Nov 13, 2011 7:02 pm
Location: Dayton, Ohio, USA

Scripting - Update

Post by Dellji »

I thought I would update you on my progress. What I wanted to do was preserve the original file and copy it to another disk drive and folder with the date appended to the original file name before I did a series of find and replace operations. Here's the code to do the save operation:

/ Get today date & time
var currentTime = new Date()
// extract month
var month = currentTime.getMonth() + 1
// extract day
var day = currentTime.getDate()
// extract year
var year = currentTime.getFullYear()
var d = month + "-" + day + "-" + year

var fso, f, s;

var pEditFile=AkelPad.GetEditFile(0); // Get file name & path
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFileName(pEditFile); // Extract file name only

// getFileName(f);
var fileNoExtension
// Will find the last dot and replace it and anything behind it with nothing.
fileNoExtension= f.replace(/\..*(?!.*\.)/, "");

// Debug statement
// WScript.Echo(fileNoExtension);

var xFilePath = "H:\\FTW-10-Data\\" // Note the double back slashes
var xGed = "ged"

// build file name
var nFilename = xFilePath + fileNoExtension + "-" + d + "." + xGed;

var hMainWnd=AkelPad.GetMainWnd();
AkelPad.MessageBox(hMainWnd, nFilename, "Find & Replace", 64 /*MB_ICONINFORMATION*/);


Hope this might help anybody else trying to do the same.

Jim

Offline
Posts: 3217
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Post by VladSh »

Dellji
Look Scripts collection.

By saving files already have the following scripts: SaveAs.js, saveStoreTime.js, OpenSaveMask.js, SaveDefault.js.
Post Reply