How to get name of current doc with js?

Help with writing and running scripts

How to get name of current doc with js?

Postby popo77 » Wed Apr 18, 2007 7:53 am

hello everyone.
I want to copy the name of active document to a variable as a string, but I find "paste" command just paste it to the file and can not set to a variable. How can I do that?
I use it like below
Code: Select all
UltraEdit.activeDocument.copyFilePath();
...
UltraEdit.activeDocument.paste();
User avatar
popo77
Newbie
 
Posts: 4
Joined: Tue Apr 17, 2007 11:00 pm

Re: How to get name of current doc with js?

Postby jorrasdk » Wed Apr 18, 2007 8:09 am

My suggestion is to use the presently undocumented path property:

Code: Select all
var filepath = UltraEdit.activeDocument.path;
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: How to get name of current doc with js?

Postby popo77 » Wed Apr 18, 2007 11:54 pm

Yeh, it does work. Thanks a lot.
By the way, I notice that the 'path' command does not list in the help file as someone(sorry, forgot your name),just in the forums, has already pointed out. Are there another unlisted commands?
Thanks for your reply again.
User avatar
popo77
Newbie
 
Posts: 4
Joined: Tue Apr 17, 2007 11:00 pm

Re: How to get name of current doc with js?

Postby popo77 » Thu Apr 19, 2007 8:13 am

Now, I try this to get the current document name only.
Code: Select all
var filepath = UltraEdit.activeDocument.path + "\r\n";
var i = filepath.lastIndexOf("\\");
var filename = filepath.slice(i + 1);


And now there is another problem, maybe it is a bug.
I want to get the current date only. not include the time. So I use below.
Code: Select all
var d = new Date();
UltraEdit.activeDocument.write(d.getFullYear() + "-");
UltraEdit.activeDocument.write(d.getMonth()  + "-");  \\ note here!
UltraEdit.activeDocument.write(d.getDate() + "\r\n");

but the result is always less than current month 1 month. I mean now it is Apri, but the answer is March. well I change it to March and get Feb instead. And only getMonth/getUTCMonth works like this.Why?
User avatar
popo77
Newbie
 
Posts: 4
Joined: Tue Apr 17, 2007 11:00 pm

Re: How to get name of current doc with js?

Postby Bego » Thu Apr 19, 2007 8:39 am

I know this behaviour from Perl. You have to add a 1 to the month. Seems a system related issue.
Maybe s.o. finds an explanation...
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: How to get name of current doc with js?

Postby jorrasdk » Thu Apr 19, 2007 8:45 am

No it's not a bug. It's WAD (works as designed) ;-) getMonth() acts like an index for an array and starts with 0 thru 11.

See more: www.w3schools.com/jsref/jsref_getMonth.asp
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: How to get name of current doc with js?

Postby popo77 » Thu Apr 19, 2007 11:38 pm

Thanks Bego and Jorrasdk.
Yeh, I completely get it now.
And Jorrasdk, it is realy very warm-hearted of you for answer my question continously, and give me the related url. It is a realy good website that helps a lot. Thanks again.
User avatar
popo77
Newbie
 
Posts: 4
Joined: Tue Apr 17, 2007 11:00 pm


Return to Scripts

cron