[Gambas-user] clipboard

Doriano Blengino doriano.blengino at ...1909...
Tue Jun 9 08:21:13 CEST 2009


Beren Scott ha scritto:
> The goal of my program is to keep an offline database and use it to plan
> out a series of actions which are html based and online. So, the
> database is accessed by my program, my program formulates with moderate
> user interaction the best course of action. The program copies a link to
> the clipboard, this link when pasted into a web browser will contain the
> decided action.
>
> There are a couple of ways I can do this, the first is to run a web
> browser and this program side by side and alt tab between them with the
> copy pasted link.
>
> If I cannot do this, then I have to incorporate the web browser directly
> into my program. I'd rather leave the browser part to the experts, but
> if possible it would be great to integrate them when I have a better
> idea of how to do this.
>
> Here is an example html link which I need entered into the clipboard:
>
> http://(server)/game.php?village=(villid)&screen=place&mode=command&target=(farmid)
>
> I can generate the string, that's the easy part, but getting it into my
> browser is going to be the hard part. There is issues with the SHELL
> option I believe due to the inclusion of "&", I don't think this is
> handled well.
>   
You can also start an external web browser from inside your program, 
passing the URL to fetch on the command line; something like:

    SHELL "firefox http://www.yoururl.whatever"

This way you avoid the burden to require the user to paste - in certain 
cases this is a difficult operation. Moreover, if required, you can also 
know when the external program terminates.

Your problem about the URL passed on a command line, is because the 
shell interprets some special chars like "?", "=" and "(" ")".

You only have to surround your parameters with a couple quotes:

	fetchurl = villurl[z - 1] & farmid[c - 1]
	SHELL "firefox \"http://" & fetchurl & "\""

Please note the --\"-- (backslash-doublequote) embedded in string constants. These are required because otherwise the shell, invoked by SHELL, would be confused from the above mentioned characters like question marks and other. You can experiment from a terminal emulator to better understand when and where quotes are required; then you replicate them inside gambas. In this case, simply a couple quotes around the url passed to firefox is required, or, only now I realize, even better is to use the single quotes - it is even simpler in gambas:

	fetchurl = villurl[z - 1] & farmid[c - 1]
	SHELL "firefox 'http://" & fetchurl & "'"


This is better because of the shell /bin/sh, which still can interpret 
some things embedded in double quotes (for example, dollar signs), but 
surely will do nothing inside single quotes. Sorry for this confusion.

Anyway, knowing about this quoting is good for everytime you use the 
SHELL command, so it is good also if you choose the xclip way. If you go 
deeper in this topic of launching external programs, take a look at 
EXEC, a little more complicated but more powerful.

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list