Linux Lite Forums

Full Version: Pass Variable To URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

[size=1em]Below we have some code that I expected would evaluate the variable %t before loading the relevant web page. It doesn't work it simply uses %t as a literal string.[/size]

Code:
/usr/bin/google-chrome-stable %U https://en.wikipedia.org/wiki/%t

[size=1em]I know the variable itself works fine so I'm wondering if the code is just badly formatted or the problem needs to be approached differently.[/size]

[size=1em]Thought this would be easy but now it's driving me mad. A green glow for the first one with a solution.[/size]
Are you wanting "%t" to prompt for search string or reference an external file?

The below would populate a blank search box within wikipedia... Might get you closer...
Code:
http://en.wikipedia.org/wiki/Special:Search?search%QUERY%

I've used apps (SlickRun) to do very similar launch google a popup box would populate or I could add the string behind..
I'd type: "google" .. a pop up box prompting for string "Linux Lite"
or I could type: "google linux lite" both would yield same...




Hi [size=1em]firenice03,[/size]


I'm passing the variable from MOCP music player.[size=1em] I want the browser to search wiki for the track that is playing. %t equates to the title of the track.[/size]


This is from the example config for mocp, it might help, didn't notice it earlier:


Code:
# Programs are run using execv(), not a shell, so you can't do things like
# redirecting the output to a file. The command string is split using blank
# characters as separators, the first element is the command to be executed
# and the rest are parameters, so if you use "echo Playing: %I" we run program
# echo (from $PATH) with 2 parameters: 'Playing:' string and the title. Even
# if the title contains spaces it's still one parameter and it's safe if it
# contains `rm -rf /`.
Shell can't see %t as a variable
Variables are marked with $t or ${t}
Code:
t="elephant"
/usr/bin/google-chrome-stable %U https://en.wikipedia.org/wiki/$t

This will do:
Code:
/usr/bin/google-chrome-stable %U https://en.wikipedia.g/wiki/"$(mocp --format %title)"
"$(mocp --format %title)" - quotes are here because the title can contain spaces and you need a whole title to be a string
here a command (mocp --format %title) output is used
edit
Oh, you want to search wikipedia. Smile
Next will open a browser and run a wiki search query
Code:
/usr/bin/google-chrome-stable %U https://en.wikipedia.g/wiki/?search="$(mocp --format %title)"

Special search:
Code:
/usr/bin/google-chrome-stable %U http://en.wikipedia.o/wiki/Special:Search?search="$(mocp --format %title)"
(11-20-2015, 09:31 PM)misko_2083 link Wrote: [ -> ]Shell can't see %t as a variable
Variables are marked with $t or ${t}
Code:
t="elephant"
/usr/bin/google-chrome-stable %U https://en.wikipedia.org/wiki/$t

This will do:
Code:
/usr/bin/google-chrome-stable %U https://en.wikipedia.g/wiki/"$(mocp --format %title)"
"$(mocp --format %title)" - quotes are here because the title can contain spaces and you need a whole title to be a string
here a command (mocp --format %title) output is used
edit
Oh, you want to search wikipedia. Smile
Next will open a browser and run a wiki search query
Code:
/usr/bin/google-chrome-stable %U https://en.wikipedia.g/wiki/?search="$(mocp --format %title)"

Special search:
Code:
/usr/bin/google-chrome-stable %U http://en.wikipedia.o/wiki/Special:Search?search="$(mocp --format %title)"

Right now I'm lifting my beer can toward the screen. Cheers! Big Grin


Just had to edit %title out of your code because apparently the docs are wrong and this in fact returns artist - title - album. Using %t with your code did the job beautifully though.