Script to search Linux Mint forums quickly

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
Lemongrass38
Level 4
Level 4
Posts: 344
Joined: Mon Dec 12, 2016 11:29 pm
Location: Central Europe

Script to search Linux Mint forums quickly

Post by Lemongrass38 » Tue Dec 20, 2016 7:43 am

Hi there!
I thought that I share with you this little script-let. It can be inserted in Autokey (available in Software Manager), and set any hotkey for them (mine is ctrl-6).

These scripts search this forum for the phrase that is highlighted with our mouse (and this way it searches for our clipboard). In fact I have no idea about Python, I've got the basic code from someone over the internet, I've rewritten only the second lines. Thought that maybe some of you will appreciate it (hope so). :)

Google Linux Mint forums search:

Code: Select all

import webbrowser
base="https://www.google.com/search?q=site:forums.linuxmint.com+"
phrase=clipboard.get_selection()

#Remove trailing or leading white space and find if there are multiple 
#words. 
phrase=phrase.strip()
singleWord=False
if phrase.find(' ')<0:
    singleWord=True
    
#Determine if phrase is a noun (or an actual title). 
#Solely syntactically for now.
name=False
if phrase.istitle():
    name=True

#Generate search URL. 
if singleWord:
    search_url=base+phrase

if (not singleWord) and (not name):
    phrase='+'.join(phrase.split())
    search_url=base+phrase
    
if (not singleWord) and (name):
    phrase='"'+phrase+'"'
    search_url=base+phrase
    
webbrowser.open_new_tab(search_url)
Last edited by Lemongrass38 on Tue Dec 20, 2016 1:02 pm, edited 2 times in total.
If your issue is solved, please be so kind and indicate that by editing the topic title in the first post. :)

Habitual
Level 13
Level 13
Posts: 4870
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: Scripts to search Linux Mint forums quickly

Post by Habitual » Tue Dec 20, 2016 8:35 am

Good stuff and I applaud your effort and your work but there is an easier way.
It works on the 2 browsers I do have and has worked for years
It's the same thing as going to a <search_engine> and

Code: Select all

<keyword site:forums.linuxmint.com
but here's the nugget.
Open a new tab and quickly site:forums.linuxmint.com try it raw. ;)
Save > 4 steps from where I sit.
It will search your default <search_engine> specified in your browser.

Enjoy the Goodness!
Wish I knew autokey, but being a SysAdmin, I can't rely on "helpers" too much. Detracts from my critical thinking processes. :)

User avatar
austin.texas
Level 20
Level 20
Posts: 12054
Joined: Tue Nov 17, 2009 3:57 pm
Location: at /home

Re: Scripts to search Linux Mint forums quickly

Post by austin.texas » Tue Dec 20, 2016 8:56 am

Google Chrome has a very useful extension - Search the Current Site. As above, you can high-light a word or phrase, then click "Search the Current Site".
Search.png
But in addition to that, I can open a new tab and (in the address bar) enter "lm search terms"
That works because I created a "keyword" called "lm"
To add a shortcut (keyword) for searching the Linux Mint Forum in Chrome:
Open Settings > Manage Search Engines > Add (at bottom)
Add a New Search: Mint Forum
Keyword: lm
URL:

Code: Select all

http://www.google.com/search?q=site#sclient=psy&hl=en&q=%s+site:forum.linuxmint.com
Mint 18.2 Cinnamon, Quad core AMD A8-3870 with Radeon HD Graphics 6550D, 8GB DDR3, Ralink RT2561/RT61 802.11g PCI
Linux Linx 2018

Lemongrass38
Level 4
Level 4
Posts: 344
Joined: Mon Dec 12, 2016 11:29 pm
Location: Central Europe

Re: Scripts to search Linux Mint forums quickly

Post by Lemongrass38 » Tue Dec 20, 2016 8:59 am

Well, I don't really understand your method... Is it :

1. open search engine
2. type site:forums.linuxmint.com
3. type whatever I wish to search for.
Is this what you wrote?

If yes, I've used it, but got tired of typing site:forums.linuxmint.com so many times. What I wrote is a bit more time to set up (install Autokey, open it, new script, copy-paste the scripts, and set a hotkey for each), but after that it's working with 2 clicks+hotkey.
If not, please let me know, what you suggested. :)
If your issue is solved, please be so kind and indicate that by editing the topic title in the first post. :)

Lemongrass38
Level 4
Level 4
Posts: 344
Joined: Mon Dec 12, 2016 11:29 pm
Location: Central Europe

Re: Scripts to search Linux Mint forums quickly

Post by Lemongrass38 » Tue Dec 20, 2016 9:02 am

Oh, I see. You created an abbreviation for it. Cool too. :) Nice to know the Chrome feature, but I don't use Chrome. Anyways, I'll mark that, if I ever need that, thank you too. :)
If your issue is solved, please be so kind and indicate that by editing the topic title in the first post. :)

Post Reply

Return to “Tutorials”