Generate txt note in XnView Browser with this Au3 code

Ask for help and post your question on how to use XnView Classic.

Moderators: XnTriq, helmut, xnview

User avatar
Brother Gabriel-Marie
Posts: 286
Joined: Thu Aug 23, 2007 2:33 pm
Location: United States

Generate txt note in XnView Browser with this Au3 code

Post by Brother Gabriel-Marie »

Hi, everyone!

Okay, I was XnViewing my archives of jpegs and decided that I wanted to make a text file where I could write notes about when and where I took all those pictures. Problem was that there was no way for me to access my Explorer Context Menu wherein lies the ever-needful command of
"Create New Text File." So I made an XnViewNoteMaker script.

The way it works is it scans the XnView window for "seeable" text and then sorts through that for the string containing the folder path used in the Small Toolbar. Then it opens Notepad in that directory and saves it automatically with a pre-defined name so you don't have to use the save
dialog. Just type some text, ctrl+s, ctrl+x and you are done.

That way I have only to write my note, name it, and save it. I don't have to hunt down a notepad link and then do the painful browse to the directory opened in XnView. All I have to do to get this into XnView's Browser Toolbar is to place the script location in the "Command" box for the Brower Toolbar. (Go to options/toolbar/browser toolbar. Now click "append" and in that new white box, paste in the path to your XnViewNoteMaker.au3 script. Then, paste the same path into the "icon" box. Voila!) You MUST have AutoIt installed however or it won't work on your computer (but you don't need to compile the script with AutoIt.)

Clever? Well, it works! (Now, I have replaced Notepad with Metapad, but it is still called Notepad. So if you use my script, you will have to read the script where I have mentioned what needs to be changed). I have only used it in Windows XP Pro. Lord knows what Vista will do.

Below is my Autoit code. Do whatever you like with it, it is YOURWARE.

-God bless!
-Brother Gabriel-Marie

Save this code into a text file and change the extension to .au3

Code: Select all

;------------------AUTO IT SCRIPT-----------------------
;Opens Notepad, types in some text and then quits.
;By Brother Gabriel-Marie
;Do whatever you like with this script, it is YOURWARE

;For this to work in XnView, you must have showing both the Toolbar and the Small Toolbar (with the address box)


#include <String>
#include <array>

$TextRetrieved = WinGetText("[Class:XmainClass]", "")

;Now sort throught the text till we find the right string
;It won't work on the title bar because XnView truncates long paths with an ellipses!
$NextText = _StringBetween($TextRetrieved, 'TBView\R', '\\\R', -1,1)


$XnViewDirectory = $NextText[0] & "\"

;Run Metapad (Notepad) in the found directory
Run("Notepad.exe", $XnViewDirectory)

;Wait for the Notepad become active - it is titled "new file - metapad" on English systems
;If you have not replaced Notepad with Metapad, switch these two following commands
;WinWaitActive("Untitled - Notepad")
WinWaitActive("new file - metapad")

;Now, if you want to automatically save the Text File, we will have to automatically name it

Sleep(200)
Send("!f") ;Alt+F opens the file menu
Sleep(100)
Send("a")  ;since the file menu is open, pushing A will "Save As"
Sleep(100)
Send($XnViewDirectory & "{!}Information.txt")
			;I put the exclamation point there so it will sort to the front the directory
			;If you don't put the exclamation in curlies, it won't work
Send("!s")    ;now save it
User avatar
JohnFredC
XnThusiast
Posts: 2010
Joined: Wed Mar 17, 2004 8:33 pm
Location: Sarasota Florida

Post by JohnFredC »

Hi!

This seemed like such a great idea, but the script fails on the first include (Line 10).

I tried putting the actual path of the include file in the parameter, but the same error occurred.

Suggestions?

Thanks
John
User avatar
Brother Gabriel-Marie
Posts: 286
Joined: Thu Aug 23, 2007 2:33 pm
Location: United States

Post by Brother Gabriel-Marie »

Well, Mr. JohnFred, I confess I am not much of a programmer; the script works on my system just fine. Do you have the latest version of AutoIt? If it failed on the include, maybe you don't have the files on your system. Also note that I replaced Notepad with Metapad. The script waits until Notepad is opened with this window title:
new file - metapad

If you have not replaced Notepad with Metapad, then the window title will be:
Untitled - Notepad
Or maybe try:

$NextText = _StringBetween($TextRetrieved, 'TBView\r', '\\\r', -1,1)
instead of:
$NextText = _StringBetween($TextRetrieved, 'TBView\R', '\\\R', -1,1)

In the StringRegEx, \r is supposed to mean carriage return. For some reason, on my computer only \R was recognized, but in the documentation there is no such thing as \R. Go figure! I don't know why. But let me know if it works.