Configure Unity Dash to forget the last command

Simple solution would be to just right-click on the dash itself and select the specific category you want to search - Dash will be cleared automatically for that.

enter image description here

I've noticed that the re-opened Dash, has the previous text highlighted. Hitting backspace key allows for clearing and carrying out new searches without issues. If only we could automate doing that . . . Well, we can with application called xdotool and a bit of scripting magic.

Install xdotool via apt-get install xdotool and save the following script. Its basic task is to determine whether or not the active window is Dash, and automate hitting BackSpace key to clear Dash. This is meant to run as python script_name.py and to be launched when user logs in by adding this script to Startup Applications.

#!/usr/bin/env python
import dbus,time,subprocess,os

def run_cmd(cmdlist):
    """ utility: reusable function for running external commands """
    new_env = dict(os.environ)
    new_env['LC_ALL'] = 'C'
    try:
        stdout = subprocess.check_output(cmdlist, env=new_env)
    except subprocess.CalledProcessError:
        pass
    else:
        if stdout:
            return stdout


def get_dbus(bus_type, obj, path, interface, method, arg):
    """ utility: executes dbus method on specific interface"""
    if bus_type == "session":
        bus = dbus.SessionBus()
    if bus_type == "system":
        bus = dbus.SystemBus()
    proxy = bus.get_object(obj, path)
    method = proxy.get_dbus_method(method, interface)
    try:
        if arg:
            return method(arg)
        else:
            return method()
    except dbus.exceptions.DBusException:
        return None

def active_is_dash():
    base = ['session','org.ayatana.bamf']
    dbus_call = base + ['/org/ayatana/bamf/matcher', 'org.ayatana.bamf.matcher','ActiveWindow',None]
    active_window = str(get_dbus(*dbus_call))
    dbus_call =  base + [active_window,'org.ayatana.bamf.view','Name',None] 
    active_name = str(get_dbus(*dbus_call))
    if active_name == 'unity-dash': return True


command = 'xdotool key BackSpace'.split()
flag = None
while True:
    time.sleep(0.25)
    if active_is_dash():
        time.sleep(0.25)
        if not flag: run_cmd(command)
        flag = True
    else: flag = False