| View previous topic :: View next topic |
| Author |
Message |
Dellji
Joined: 13 Nov 2011 Posts: 3 Location: Dayton, Ohio, USA
|
Posted: Sun Nov 13, 2011 7:10 pm Post subject: Scripting |
|
|
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 |
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1067 Location: Poland
|
Posted: Sun Nov 13, 2011 7:26 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Dellji
Joined: 13 Nov 2011 Posts: 3 Location: Dayton, Ohio, USA
|
Posted: Mon Nov 14, 2011 1:14 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Dellji
Joined: 13 Nov 2011 Posts: 3 Location: Dayton, Ohio, USA
|
Posted: Tue Nov 15, 2011 9:04 pm Post subject: Scripting - Update |
|
|
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 |
|
| Back to top |
|
 |
VladSh
Joined: 29 Nov 2006 Posts: 2509 Location: Êèåâ, Ðóñü
|
|
| Back to top |
|
 |
|