Desktop Scanner

Suppose one wants to be more focused, however there are so many possible distractions. Having a measure of how many possible distractions one has open can help - similar to how displaying fuel efficiency changes driving behavior.

Furthermore, one may have certain windows open when working in a non-impacting test environment, and other windows open when touching production. This monitoring can minimize the number of mistakes and improve the use of read-only accounts.

The below code runs by searching for screenshots placed in the same directory as the script - these are png files (note that they need to be re-copied each time the script is updated). It runs as:

Bordens-iMac% ./SikuliX-IDE.app/Contents/runIDE -r ./scan_desktop_impact.sikuli
running SikuliX-IDE: -Xmx512M -Dapple.laf.useScreenMenuBar -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine
-jar ./SikuliX-IDE.app/Contents/sikuli-ide.jar -r ./scan_desktop_impact.sikuli
[info] add hotkey: ⌃ F5
Press Control-F5 to quit
_______________
****
_______________
**
_______________
*

Every 3 seconds the code prints two lines - a line of underscores for the number of screenshots in the directory, and a star for each of the screenshots that are matched. A video of this is:


The code is:

from sikuli import *
import sys
import os

# Scan a directory for images and show the number of counts of matching on the screen.
# Exit when Control-F5 is hit.

Settings.UserLogs = True
Settings.UserLogTime = True

# Added hotkey to quit easily
# http://doc.sikuli.org/globals.html#listening-to-global-hotkeys
def quitFromKey(event):
    Debug.user("User selected to exit")
    exit(0)
    # exit            # stop the current script, using exit(0) will close the IDE.

# When the user pressed Ctrl+F5 exit this script

Env.addHotkey(Key.F5, KeyModifier.CTRL, quitFromKey)
print "Press Control-F5 to quit"

# Revert this with:
# Env.removeHotkey(Key.F5, KeyModifier.CTRL)

# run for 8 hours, sleeping every 3 seconds.
# run_time = 60 / 3 * 60 * 8
# run for 25 minutes - 1 pomodoro
run_time = 25 * 60 / 3
while run_time > 0:
    count = 0
    found_images = 0
    for f in os.listdir(getBundlePath()):
        # Debug.user(f)
        if f.find(".png") != -1:
                count = count + 1
                if exists(f):
                    found_images = found_images + 1
                       # Debug.user("Found a prod image")

    if(count == 0):
        print "ERROR: Images not found - place files in ",getBundlePath()
    else:
        print " ","_" * count
        spaces = " " * (count - found_images)
        stars = "*" * found_images
        print spaces,stars
    sleep(3)
    run_time = run_time - 1
exit(0)