Please help with this macro (to grab text from webpage)

pajenn's picture

Okay, here's my first macro. It's meant to save selected text from a website into the last directory that was used for notepad:

save text as <_anything> = {shift + c} Wait(100)
ShellExecute("Notepad") Wait(500)
{Ctrl+v} Wait(100)
{Ctrl+s} Wait(100) $1{Enter};

It works okay, but I wanted to use it with Notepad2 instead of Notepad, however, the command fails when I change "Notepad" to "Notepad2 - AppBringUp(Notepad2) doesn't do the trick either even though the voice command "Open Notepad2 does work."

Notepad2: http://www.flos-freeware.ch/notepad2.html

Also, does anyone know a small app that could clean up text so that if I "select all" on a webpage, and copy/paste it to notepad, the app would cleanup the html code, and just leave mostly clean text. (I ran across something called PureText that I thought was supposed to fit the bill, but it didn't work for me, or maybe it was meant for something else).

On a related matter, I'm in the process of turning my supplemented right-click mouse menus into voice commands, and it would save me some time if someone could give me the basic structure to use.

I'm using something called FileMenu Tools: http://www.lopesoft.com/en/fmtools/info.html

It adds items to your mouse's right-click (sub)menu in Windows Explorer. For example, I'd like to be able to highlight a file and say "copy name" or "move to" and have DNS execute the corresponding FileMenu Tool command.

Thanks.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Note that the copy of

Note that the copy of "Notepad2" I have is actually titled "Notepad++". When I say "switch to Notepad plus sign plus sign", the focus shift to that application, but not when I substitute "Notepad two". So maybe that's what you need.

BTW, congratulations on your first macro!

Bruce

pajenn's picture

Notepad++ is different:

Notepad++ is different: http://notepad-plus.sourceforge.net/uk/site.htm

It's primarily a free source code editor whereas Notepad2 is mainly just a small, light text editor, but with a tad more functionality than Notepad. For example, Notepad2 knows to insert line breaks in places that originally had line breaks, whereas Notepad sometimes substitutes little empty square symbols for them.

Yikes! I'm the pig here: I

Yikes! I'm the pig here: I got too much stuff on my plate. I think I found Notepad++ via the link on Notepad2's page (http://www.flos-freeware.ch/notepad2.html), which may be why I've confused them for sometime now.

Bruce

pajenn wrote: Also, does

pajenn wrote:

Also, does anyone know a small app that could clean up text so that if I "select all" on a webpage, and copy/paste it to notepad, the app would cleanup the html code, and just leave mostly clean text. (I ran across something called PureText that I thought was supposed to fit the bill, but it didn't work for me, or maybe it was meant for something else).

On a related matter, I'm in the process of turning my supplemented right-click mouse menus into voice commands, and it would save me some time if someone could give me the basic structure to use.

I'm using something called FileMenu Tools: http://www.lopesoft.com/en/fmtools/info.html

It adds items to your mouse's right-click (sub)menu in Windows Explorer. For example, I'd like to be able to highlight a file and say "copy name" or "move to" and have DNS execute the corresponding FileMenu Tool command.

Thanks.

Might I suggest you'll get better feedback and we'll all lead slightly more organized online existences if you post one query per topic?

FWIW, I can't help with these last two queries.

Sorry,
Bruce

Try ShellExecute("Drive:\Note

I don't think Notepad2 registers itself on your path.

Try :
ShellExecute("Drive:\Notepad2Dir\Notepad2.exe") Wait(500)

I have not tried the code but "D:\Notepad2\Notepad2.exe" works for me in the run command, whereas "Notepad2" by itself does not.

Mark

pajenn's picture

Success! Thanks. That

Success!

Thanks. That worked.

Here's the corrected macro (correction/change in bold) to be used on "selected" text:

save text as <_anything> = {Ctrl + c} Wait(100)
ShellExecute("C:\Program Files\notepad2\Notepad2.exe") Wait(500)
{Ctrl+v} Wait(100)
{Ctrl+s} Wait(100) $1.txt;

I added the ".txt" because Notepad2 will otherwise save it without any extension. and I dropped the {Enter} at the end, so that I have a chance to verify the <_anything>-name and change the target directory. Not sure if the Wait() times are optimal, but the macro doing what it's supposed to.

the times inside the wait

the times inside the wait are going to be converted to seconds in newer releases of NatSpeak. So Wait(100) must become Wait(0.1) from version 8 onwards I believe. Or does vocola make an exception here?

The times seems sensible to me.

Quintijn

pajenn wrote: Not sure if

pajenn wrote:

Not sure if the Wait() times are optimal, but the macro doing what it's supposed to.

As I've recently pointed out, "optimal" is often undefined in a conversation. But in this case, most of us would agree that "optimal" means "minimal", or "as little as possible". I know of no way to determine that value except to experiment until you find it.

If you don't mind the speed of the macro, then maybe the best use of your time is to leave it and move onto making the next one. But if you do want to "optimize" it, cut your Wait parameter in half until the macro stops working. Then take half the range between that value and the last successful value. This is a well-known search stragegy and is probably most efficient over the long haul as you write multiple macros with Wait statements.

Bruce

BruceCyr wrote: As I've

BruceCyr wrote:

As I've recently pointed out, "optimal" is often undefined in a conversation. But in this case, most of us would agree that "optimal" means "minimal", or "as little as possible".

I would venture to suggest that optimal means "most favorable" Smiling
Quentin

pajenn wrote: Also, does

pajenn wrote:

Also, does anyone know a small app that could clean up text so that if I "select all" on a webpage, and copy/paste it to notepad, the app would cleanup the html code, and just leave mostly clean text. (I ran across something called PureText that I thought was supposed to fit the bill, but it didn't work for me, or maybe it was meant for something else).

Seems to me you need to find a programmable editor for which you can write an internal script that does the stripping and then feeds the output back into your own script stream. In principle I think you could do this with M$ Word, but there are probably a number of programmers' editors that would be better simply because they could open, work and shut down much faster than Word.

Bruce

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Syndicate content