Debugging Scripts

For debugging Debugging Scripts scripts, several things are helpful:

  • From the scripting guide - just displaying simple text helps:

    Settings.UserLogs = True
    Settings.UserLogTime = True
    
    Debug.user("Start of READ_DOC script")
    Debug.user(getBundlePath())

    This will print the following in the message section:

    [sikuliLog (1/11/15 1:11:14 PM)] Start of READ_DOC script
    [sikuliLog (1/11/15 1:11:14 PM)] /Users/sunflower23/SikuliX/read_doc.sikuli/

    When taking examples, such as this, print "string" should be replaced by Debug.user("string")

  • It is useful to display what region is being evaluated - the following will display a red rectangle around the Safari application:

    myApp = App("Safari")
    myApp.focus()
    myApp.focusedWindow().highlight(2)

    For this to work, the following option must be selected so Sikuli can take control:

    Security and Privacy - Allow app to control your computer
    If this is not done, when the script is executed it will have the error:

    Check "Enable access for assistant devices" in the System Preferences and then close this dialog.

  • Running Sikuli - This page has some tips on running Sikuli script independently of the IDE, as an example:

    Bordens-iMac% ls -dl ./SikuliX-IDE.app/Contents/runIDE ./scan_desktop_impact.sikuli
    -rwxr-xr-x  1 sunflower23  staff  1148 Dec 11 21:14 ./SikuliX-IDE.app/Contents/runIDE
    drwxr-xr-x  4 sunflower23  staff   136 Jan 26 22:01 ./scan_desktop_impact.sikuli
    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
    [user (1/27/15 9:03:51 PM)] Start of scan_desktop script.

    One interesting discovery about the IDE - Each time a script is saved, the png files in that directory that are not listed in the script are cleaned out!