selected text in revBrowser

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

selected text in revBrowser

Post by jrioux » Sun Dec 23, 2012 1:43 pm

Does anyone know whether revBrowserGet(id, "selected") will get selected text from a pdf? It keeps coming up "no selection" for me.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: selected text in revBrowser

Post by sturgis » Sun Dec 23, 2012 6:35 pm

Since the pdf is actually handled by acrobat, the livecode interface (and javascript for that matter) don't seem to understand about embedded pdfs.

However, I found a way on mac (the only platform I can test on at the moment) where you can still get the job done.

Using the following applescript:

Code: Select all

tell application "System Events"
keystroke "c" using {command down}
end tell
All this does is to send the systemwide copy keypress, whatever is hilighted in the current window is copied to the clipboard and can then be accessed using

the clipboarddata["text"]

To execute the applescript, place it into a card property (perhaps named ascript) then

Code: Select all

do the ascript of this card as "applescript"
I can't test with vbscript, but i'm sure something similar can be done there as well. Have tested it with a valid pdf in a browser instance and it seems to work fine.

If you need an answer on windows something like this may work. (it should be close to what you need)

Code: Select all

Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.SendKeys "^{c}" ' send Ctrl+C, copy to clipboard
Place this in a property as mentioned above then

Code: Select all

do the vbscript of this card as "vbscript"
if it works, then same as with the applescript, the data should be in
the clipboarddata["text"]


The only negative i've seen so far is that you must actually click the browser instance to make sure its front and active, otherwise you might not get the copied data you are looking at. There might be a way to force the browser instance to the front to ensure you get the right copy, but that will take more digging into applescript and vbscript to figure out.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Sun Dec 23, 2012 9:17 pm

Many thanks, sturgis. I wish I'd known I couldn't access it directly before I started down this road, but a workaround is just that - it works, and that's OK. :-)

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Mon Dec 24, 2012 12:39 am

I'm getting this to work in the IDE (Mac), but not in a standalone. Any thoughts?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: selected text in revBrowser

Post by sturgis » Mon Dec 24, 2012 2:35 am

You'll need to add menu items to your standalone system menu. The easiest way is with menu builder. I don't know much about menu builder, so actually making menus that work as you wish is another area that you're on your own, but just for a quick test..

I added a menu using menu builder. In one of the dialogs I chose "yes move my stuff down to make room."

Didn't change or add any scripts to the objects.

Saved, the whole shebang, built the standalone, and voila' It works.

THe problem before is that there was no code (in this case accelerator keys from the meny) to catch the cmd-c keypress from the applescript. Adding the menu takes care of this and it now works fine in standalone.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Tue Dec 25, 2012 3:27 pm

OK. So, given I need an edit menu, is there a way I can "trigger" the copy item of that menu using code? That way, I would have a cross-platform solution that wouldn't require applescript or the Windows equivalent.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: selected text in revBrowser

Post by sturgis » Tue Dec 25, 2012 4:12 pm

I tried manually using "copy" and/or various other methods to get text to copy from an embedded pdf and couldn't get it to work. Going to the system and invoking the keypress for copy does. At which point if you have the menu set up which allows for the accelerator keys, then things work. If you are good at c/c++ you could probably write an external to do this, but I don't see another way at the moment. Maybe someone will chime in with an alternate idea.

Having said that though, its easy enough to branch the code with a switch block, or 'if' to call OS specific code. I'm pretty sure (without being able to try it) that the vbscript version will be pretty simple also.

It might also be possible to use a javascript method to talk to the plugin. (revbrowserexecute) But the few things I tried that way didn't work either. Using javascript to get hilited text in a regular page? Easy. As soon as you try to do it with an embedded pdf, no luck.

Also, I was just thinking. Rather than insert a whole menu, you can probably just add a button with no code, that is set up to use the same accelerator keys (command c in this case, or on windows ctrl-c)
THis way the keypress will be accepted (just like with the menu) and since the app does nothing with it, the system will hopefully take over and do the copy. This way you can avoid having to deal with the menu builder entirely. (THough I haven't tried it yet)

I'll try to get access to a windows machine and locate a vbscript that will work for this.
jrioux wrote:OK. So, given I need an edit menu, is there a way I can "trigger" the copy item of that menu using code? That way, I would have a cross-platform solution that wouldn't require applescript or the Windows equivalent.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Tue Dec 25, 2012 10:55 pm

OK. I was able to copy selected PDF text to the clipboard using the menu in a compiled app (no need to go the AppleScript route), but wondered whether I could achieve this using code, bypassing the menu. I imagined that the menu was trapping the copyKey command and (as it should) copying the selection to the clipboard, but wondered whether I might duplicate that function myself, outside the menu.

I was wondering where the scripts for the MenuBuilder scripts reside. If I could find the Edit menu script, I could duplicate it in a Submit button I am having the user press, copying the selection to the clipboard, and thereby making it accessible to the app.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Tue Dec 25, 2012 11:41 pm

I'm finding this reference to "the system" interesting (e.g., a copyKey not handled by the app will be handled by the system). Shouldn't the simple statement "send copyKey in 0 milliseconds" achieve the same result as calling the AppleScript?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: selected text in revBrowser

Post by sturgis » Wed Dec 26, 2012 3:39 am

Just messed with dispatching copykey, doesn't seem to work. (even if you suspend the dev environment as required)

copykey is a message that is sent when the keys are pressed so that you can handle things differently, but in the case of these darn embedded pdfs, it seems that staying out of the way and letting the system handle it is the only way i've been able to get it to work.

Maybe someone else has a better idea (or an external) that can handle it in a better way.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Thu Dec 27, 2012 3:00 am

Many thanks, sturgis. I benefit from your experience.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Thu Dec 27, 2012 4:34 pm

Mac's OK. Windows no go.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: selected text in revBrowser

Post by sturgis » Thu Dec 27, 2012 5:57 pm

Ah well. Just got my machine set up but haven't figured out a workaround for windows yet. If I do I'll let you know. You might consider posting your question to the mailing list. While there is some crossover between there and here, not everyone is both places, and you never know who might have just the right clue.

If you are handy with C, c++ the external way might be the easiest fix. Or contact Monte and see what it would cost for such a beast. (Shouldn't be much to it) Not sure if he does all platforms or not though. (sigh) I even went to far as to try and use the type command to get it done, but no luck. (will keep experimenting with vbs and try to think of other options to get this working) Of course telling the user to type ctrl-c will probably work fine (if the empty menu items are there) Doesn't really help with the automated copying of stuff though, so i'll keep trying a few things.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: selected text in revBrowser

Post by jrioux » Tue Jan 01, 2013 6:02 pm

OK. So I decided to bypass revBrowser altogether and just use an rtf version of the text in a Livecode field. Thanks for the help, sturgis.

Post Reply

Return to “Internet”