Page 1 of 1
Scripting
Posted: Sun Nov 13, 2011 7:10 pm
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
Posted: Sun Nov 13, 2011 7:26 pm
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.
Posted: Mon Nov 14, 2011 1:14 am
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
Scripting - Update
Posted: Tue Nov 15, 2011 9:04 pm
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
Posted: Wed Nov 16, 2011 9:16 am
by VladSh
Dellji
Look
Scripts collection.
By saving files already have the following scripts:
SaveAs.js,
saveStoreTime.js,
OpenSaveMask.js,
SaveDefault.js.