Friday, October 7, 2011

How to : Turn Autokey into super search application

First make script for "search invoke" and "search". There are 2 ways "search invoke", user input or direct search. For user Input I use this script:


result, text = dialog.input_dialog(title="Search", message="What do you want to search?")
if (result == 0  and text != ""):
    engine.run_script("search")


For direct search:



text = clipboard.get_selection()
if (text != ""):
    engine.run_script("search")



Please note that the text in blue is the name of the "search" script. You also have to bind keys to this script. As an example I use "super" + "space" for user input and "super"+"shift"+"space" for direct search because my experience on Gnome-Do, where they use the same button. But you can bind it any keys, that you find more comfortable.
The second part is the "search" script. The idea is actually pretty simple here. You have the text you want to search, you want to search that on the web and later your want web browser to open the page. Here is the default of my little super search application:

#First part - Youtube search

if(text[0:2]== "y "):
    text = text.replace(' ','+')
    system.exec_command("chromium-browser http://www.youtube.com/results?search_query=%s" %text[2:])
#Second part - default 
else:
    text = text.replace(' ','+')
    system.exec_command("chromium-browser http://www.google.de/webhp#q=%s" %text)   


Now I can search on specific website. But to do that I have to put some code to put it at work. In this case, to search on youtube I have to write "y " first, then after that the text I want to search. For default I will use google search.
These also some example of what it can do. Just copy paste it between first part and second part.

#Update computer

elif(text=="update"):
    system.exec_command("gksudo apt-get update && gksudo apt-get upgrade")

#Open multiple website
elif(text=="pack1"):
    system.exec_command("chromium-browser https://mail.google.com/mail/")
    system.exec_command("chromium-browser https://www.google.com/reader")
    system.exec_command("chromium-browser https://www.google.com/calendar/")

#Tell time or date
elif(text=="time"):
    date=system.exec_command("date +%T")    
    result, text = dialog.input_dialog(title="%s" %date, message="What do you want to search?")
    if (result == 0  and text != ""):
        engine.run_script("search")
elif(text=="date"):
    date=system.exec_command("date +%F")    
    result, text = dialog.input_dialog(title="%s" %date, message="What do you want to search?")
    if (result == 0  and text != ""):
        engine.run_script("search")

#Open application with our own keyword
elif(text=="terminal"):
    system.exec_command("gnome-terminal")


Please note that this code work if you have chromium browser. For another browser you have to change the word "chromium-browser" in the last line with another browser command.

No comments:

Post a Comment