Passing clipboard content to bash variable

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
fmen
Posts: 51
Joined: Mon 07 May 2018, 12:22

Passing clipboard content to bash variable

#1 Post by fmen »

#!/bin/bash

url = 'xclip -o -selection clipboard'
/usr/bin/palemoon url

# clipboard content is "www.my.yahoo.com"
# result: palemoon opens url.com not yahoo

# xenialpup 7.5 64bit
# Can anyone tell this newbie where I went wrong? Thanks.

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#2 Post by goingnuts »

Haven't tested but maybe it should be:

Code: Select all

url=$(xclip -o -selection clipboard)
/usr/bin/palemoon $url

fmen
Posts: 51
Joined: Mon 07 May 2018, 12:22

#3 Post by fmen »

Thanks, but no go. Browser opens home page now. Looks like is not grabbing clipboard content.

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#4 Post by goingnuts »

Then you must work with the command

Code: Select all

url=$(xclip -o -selection clipboard)
What is the output of

Code: Select all

echo $url
?
Alternatively

Code: Select all

echo ${url}
Just to verify - what is the output of

Code: Select all

xclip -o -selection clipboard
?

fmen
Posts: 51
Joined: Mon 07 May 2018, 12:22

#5 Post by fmen »

Ok, the output of :

Code: Select all

xclip -o -selection clipboard
and

Code: Select all

xclip -o clipboard
Produces the clipboard url "my.yahoo.com"

Code: Select all

echo url
produces output "url"

Code: Select all

echo $url
produces nothing[/code][/quote][/code]

fmen
Posts: 51
Joined: Mon 07 May 2018, 12:22

#6 Post by fmen »

Solved!!

Even simpler is the following...

Code: Select all

/usr/bin/palemoon $(xclip -o)

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#7 Post by Keef »

Try sending the output to a temporary text file:

Code: Select all

xclip -o -selection clipboard > clip.txt
url=$(cat clip.txt)
echo $url
If you paste this straight into a terminal, and run it, then url will equal the above code, as it will always be the last thing copied.

[EDIT] Looks like you got a better answer anyway.

fmen
Posts: 51
Joined: Mon 07 May 2018, 12:22

#8 Post by fmen »

I appreciate that there are more than one way to get results. Thanks.

The reason for this exercise was to be able to write a small script that opens chromium urls in palemoon.

http://murga-linux.com/puppy/viewtopic. ... 577#992577

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#9 Post by musher0 »

Hi fmen.

I suppose that you already know that if you type an URL such as
www.my.yahoo.com in console (or you can paste it in the console with
middle-click from anywhere) and then single-left-click on it, this URL will
open in your default browser.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#10 Post by tallboy »

musher0, that depends on which terminal you use, and how it is set up. Traditionally, mouse clicks don't have anything to do in a term window! :x
True freedom is a live Puppy on a multisession CD/DVD.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#11 Post by musher0 »

tallboy wrote:musher0, that depends on which terminal you use, and how it is set up. Traditionally, mouse clicks don't have anything to do in a term window! :x
Tallboy,

you made me fall off my chair! :lol: Please explain!

Don't all Puppies come with gpm (the "general purpose mouse") installed at
/usr/sbin/gpm and /usr/lib/gpm, and activated through /etc/init.d/gpm?

Plus: this cannot be all wrong, can it?
https://wiki.archlinux.org/index.php/Co ... a_terminal

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#12 Post by tallboy »

musher0, I use a urxvt terminal window.
I can paste previously selected text by a middle-click.
With the left button, I can select text in a terminal window by dragging, double-clicking or triple-clicking, and the text is copied.
If I click on text in the terminal, nothing happens, unless I start dragging it to select some text.
I have never been able to single-click on an url to make it open in a browser.
Neat trick, but it must create trouble if you just click to start copying some text?
True freedom is a live Puppy on a multisession CD/DVD.

hamoudoudou

Programming section : Click in terminal

#13 Post by hamoudoudou »

What i know is that previous commands are in history
if you type first your preferred sites, then use history
i ws just checking topics in this programmers forum.. Yes, really not my cup of tea..

Post Reply