User Tools

Site Tools


programming:scripts

Helpful Scripts

Are we preparing for this future? I look around, and see a generation of bright, inventive designers wasting their lives shoehorning obsolete interaction models onto crippled, impotent platforms. I see a generation of engineers wasting their lives mastering the carelessly-designed nuances of these dead-end platforms, and carelessly adding more. I see a generation of users wasting their lives pointing, clicking, dragging, typing, as gigahertz processors spin idly and gigabyte memories remember nothing. I see machines, machines, machines.

Bret Victor in Magic Ink

software should not be so lazy; it should stop making the user do work that the computer is better suited to doing (e.g. remembering where they put files), and it should stop making users go through the same steps over and over again, as if it were the first time they had ever met this user.–A review of The Inmates are Running the Asylum

More ideas in The Inmates are Running the Asylum, About Face, and The_Humane_Interface

  • A more recent guy is Paul Chiusano, who states that “Worse is Better” is NOT true (CSS is unneccessary). Also, suggesting relevant “things to do” based on currently selected type here.

Today I was forced to edit a Microsoft Word document, containing comments (made by me, and by others) and tracked changes. I found myself wanting to delete all comments, and accept all tracked changes. It took a few minutes to figure out, and I very quickly gave up trying to actually discover the functionality within Word’s actual UI and resorted to using Google. God help me if I wanted to, say, delete only comments made by me within the last ten days.

Automatic Script Suggestion

Point p = b.GetClickablePoint();
 
// Move the mouse to the point. Then click
Mouse.MoveTo(p);
Mouse.Click();

Algorithm

The problem is to discover what is a repeated thing, with insertions of irrelevant things. (no deletions or reorderings I think…)

For now, make a hash table that, given each event (mouse click, keyboard sequence (to prevent taking too much time), screen refresh with new data??, etc.), stores the offset in the log that it exists. Then do a “find common sequence” run on each of the instances of that event and see if they match.

  • Probably not great, but we'll work with it for now.

UI Automation Tools

UIAutomation

  • Great C# up and running here. Some Microsoft advice (sorta) on FindFirst
  • Subscribe to changes in tree here
  • IronPython? It's a redo of CPython and doesn't support numpy, etc. Don't use

Doesn't support right click out of the box? LabelControl, like Vimium mouseless browsing for the whole Windows OS! Upgrade with UI Automation / AutoIt? (seems overkill but works well enough)

Use Cases

  • “Renew all library books”, does the 4 commands you need, maybe in a separate window so you can do other stuff?
  • Setting program options without Googling, hunting, and pecking all the time.
  • “Why is my playlist not going to the next song?” (one of the repeat modes is turned on)

Need to enable “accessibility mode” in Chrome:chrome://accessibility/

List_of_GUI_testing_tools Ranorex is a nice tool too! Squish is rather expensive…

  • Automa is a great (commercial) tool for quick automation. However slow!
    • Includes image-based clicking and regular expressions
    • However, it's quite slow in practice!
  • AutoIt and PyHook (they only records pixel position information and not menu trees, etc >.<)
  • Sikuli uses OpenCV SIFT features to find the objects again, kinda cool! But … big and kloogy seemingly too.
  • So far going with PyWinAuto and maybe SWAPY to help too. (Windows only though)
    • Why don't go with it?
      • Can't find panes in Microsoft Word, etc. So, doesn't support UIAutomation API, only MSAA
      • Can only traverse menu items. Doesn't support searching other tree styles. (Their example for clicking paintbrush in Paint uses pixels, a big no-no)
    • Caches tree as it explores it in Python (local variables).
    • Uses pywin32

Ubuntu HUD in Windows

Ubuntu Automation

  • Several…ldtp (but can't get it working). Dogtail (old?), and PyUseCase, which is meant for describing use cases in words, but I can't find where it records the “path to button” information.

Success in Python! here (accesses Windows COM for UIAutomation, then you can call commands interactively on it!). Another is here

  • Make a separate thread?? Only if you are calling your own automation GUI, it seems
    • “Callbacks are safe, as they are executed in a non-GUI thread (and your automation client doesn't have a GUI)”

MAKE A SEPARATE THREAD (that doesn't get in way of user)

  • Windows Inspect tool is listening toolkit in Windows SDK. Traverse menu items and buttons…
    • Located at: C:\Program Files\Windows Kits\8.1\bin\x86\inspect.exe in Windows 8, whereas in Windows SDK v. 7, it's at C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin (on Quicksilver)
  • White seems like a nice cross-toolkit automation toolkit (Windows only though)

Installing Accerciser (Inspect for Ubuntu)

git clone git://git.gnome.org/accerciser
cd accerciser
sudo apt-get install libgtk-3-dev python-gobject-dev libatspi2.0-dev intltool
autoreconf -fi #They're using autoconf, which this command is the proper command
./configure
make
  • But make is complaining on Makefile missing separator >.<

Great article by UI interaction designer that worked at Apple.

  • Engineers tend to remember things very well, whereas the average person does not. I certainly do not remember names of things, but I do remember what they look like
  • You can elegantly support both in your app (like iOS Contacts, but better)
  • Mac/spotlight/iOS currently does not support fuzzy search if you misspell or don't know what you are looking for. REALLY DUMB. Things like Google's “Did You Mean” is required stuff.
  • Aunt Sandi:
    • “Why is the song playing over and over again?” –> “repeat song”.
    • “How can I not insert the CD over and over in order to play the music”? –> “'rip' a CD”

Smart Code Suggestion

Not always do I remember the name of a function? Why not search the docs for the functions too?

Gmail Keyboard Shortcuts

No collapse all keyboard shortcut??!?!?! ARGH

Web Automation

Selenium seems a great option, but only runs once after page load. Best to go with WebDriver (also included) which is a direct talker to the browser and allows waiting for AJAX stuff.

Regular Expressions

Unless performance is of utmost concern, it's often easier just to run your results through a second pass, skipping those that match the words you want to negate.

Regular expressions usually mean you're doing scripting or some sort of low-performance task anyway, so find a solution that is easy to read, easy to understand and easy to maintain. –Bryan Oakley

Also known as regex. Great tester at Regex101 Sticking with Python for now.

^ - match start of line
$ - match end of line
() - group 
? - something previous is optional
Description Code
Match except certain chars (* in this example) [^*]
Match except certain words (foo) ??
Stuff nearby stuff foo[\w\W]{1,1000}PMEMDev

Finding Stuff

Grepwin doesn't support searching the results again m(

Going with DocFetcher for now.

Lucene/DocFetcher Search Tips

“foo bar”~20 foo and bar within 20 words of each other
  • But HECI1_CSE_FS_OPSTATE_ can't find the string HECI1_CSE_FS_OPSTATE_CM3_NOUMA but *CM3_NOUMA can. But CM3_NOUMA can't.

Unix

Keyboard completion from history. <Ctrl+R> then up arrow works out of the box. But just up arrow is solved with https://askubuntu.com/a/59855

grep -rn "string" . > search.txt      # Search for "string" in all files down from current directory
bash --login                          # Refresh terminal (reload .bashrc)
foo <Ctrl+R>                          # Search history for "foo" and display results??! //unverified//

Windows

Batch File

@ECHO off 
 
::Delete all stats files
 del %CD%\*.stats
 
for %%s in ("unit_test","integration_test") do (
	echo %%~s
 
	for %%X in (%%~s\*.mf) do ( 
 
		java simulator/framework/Elevator -head head.txt -cf %%~s/%%~nX.cf -mf %%~s/%%~nX.mf
		echo %%~nX
		:: Hold for a few seconds
		PING google.com -n 2 -w 60 > NUL
	)
 
	move /Y *.stats %%~s/
 
)

Terminal

//Windows
C:\> mklink /D C:\TestFolderLink C:\Users\Geek\TestFolder
symbolic link created for C:\TestFolderLink <<===>> C:\Users\Geek\TestFolder
//Unix
ln -s <thing you are pointing to> <pointer name>
ln -s /usr/var/foo/bar /home/nhergert/ptr
  • How to “mirror” a website with wget (from Fosswire
//Creates a backup of only the subfolder and waits 20 seconds. Also follows links?
wget -mk -w 20 -np http://example.com/subfolder/
  • How to limit your bandwidth (for testing websites, etc). From MacWorld
Example:
//Create a 15KB/s limited pipe
sudo ipfw pipe 1 config bw 15KByte/s
//Attach the pipe to port 80
sudo ipfw add 1 pipe 1 src-port 80
//Remove the pipe (gotta remember this one!)
sudo ipfw delete 1
  • How to quickly upload to web server using SCP more here
scp      <src>                         <dest>
scp filename.ext nolanher@nolanhergert.com:~/public_html/share/ 
mogrify -quality 100 -format jpg *.pgm //Batch convert all pgm files to jpg with quality of 100% and preserve filenames
scp *.jpg nolanher@nolanhergert.com:~/public_html/dokuwiki/data/media/robotics  //Upload to web server
  • Screen grab a unix machine!
unix> ssh username@serveraddress.edu -X
unix> Connecting...ssh details...You're in!
unix> synaptic / matlab / browser / etc.

  • Skip using passwords for SSH (generate SSH keys)
ssh-keygen -t dsa
#Hit return for everything
scp ~/.ssh/id_dsa.pub nolanher@nolanhergert.com:.ssh/temp
ssh nolanher@nolanhergert.com  #Log into web server
cat .ssh/temp >> .ssh/authorized_keys  #Appends to authorized_keys in case you have multiple logins

AutoIT

Window interaction in Windows. Allows you to find pixel colors too. Function listing http://www.autoitscript.com/site/

AutoHotKey

;Copy some OS X keyboard functionality
 
!Left::Send  {Home}
!Right::Send {End}
!+Left::Send {LShift down}{Home}
!+Right::Send {LShift down}{End}
!Up:: Send   {PgUp}
!Down::Send  {PgDn}

Makefiles

  • Using c99 standard allows for one-liner (//) comments
  • Below is a slightly modified Makefile from my proxy lab for 15-213

Makefile
CC = gcc
 
#Compiler flags
CFLAGS = -g -Wall -std=c99
 
#Linker flags
LDFLAGS = 
 
#Should be same name as executable on bottom
#but...might not be necessary
all: proxy
 
csapp.o: csapp.c csapp.h
	$(CC) $(CFLAGS) -c csapp.c
 
proxy.o: proxy.c csapp.h
	$(CC) $(CFLAGS) -c proxy.c
 
#This needs to have the same name as one of your input files?!
proxy: proxy.o csapp.o
 
#Creates a gzip file of sources only
submit:
	(make clean; cd ..; tar czvf proxylab.tar.gz proxylab-handout)
 
clean:
	rm -f *~ *.o proxy

Number Manipulation

  • “Map” from one scale to another. Used in Processing and Arduino
int pos = map(dist, 0, 1023, 0, 180);
int map(int x, int in_min, int in_max, int out_min, int out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
programming/scripts.txt · Last modified: 2018/05/03 14:31 by admin