AkelPad Forum Index AkelPad
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scripting

 
Post new topic   Reply to topic    AkelPad Forum Index -> Discussion (English)
View previous topic :: View next topic  
Author Message
Dellji



Joined: 13 Nov 2011
Posts: 3
Location: Dayton, Ohio, USA

PostPosted: Sun Nov 13, 2011 7:10 pm    Post subject: Scripting Reply with quote

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
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1326
Location: Poland

PostPosted: Sun Nov 13, 2011 7:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dellji



Joined: 13 Nov 2011
Posts: 3
Location: Dayton, Ohio, USA

PostPosted: Mon Nov 14, 2011 1:14 am    Post subject: Reply with quote

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
View user's profile Send private message
Dellji



Joined: 13 Nov 2011
Posts: 3
Location: Dayton, Ohio, USA

PostPosted: Tue Nov 15, 2011 9:04 pm    Post subject: Scripting - Update Reply with quote

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
View user's profile Send private message
VladSh



Joined: 29 Nov 2006
Posts: 2605
Location: ,

PostPosted: Wed Nov 16, 2011 9:16 am    Post subject: Reply with quote

Dellji
Look Scripts collection.

By saving files already have the following scripts: SaveAs.js, saveStoreTime.js, OpenSaveMask.js, SaveDefault.js.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Discussion (English) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


SourceForge.net Logo Powered by phpBB © 2001, 2005 phpBB Group