From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / OSX / fuzztest.sh
1 #!/bin/sh
2 # Copyright © 2016 Jamie Zawinski <jwz@jwz.org>
3 #
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation.  No representations are made about the suitability of this
9 # software for any purpose.  It is provided "as is" without express or 
10 # implied warranty.
11 #
12 # Deliver random rotate and shake gestures to the iOS Simulator window.
13 #
14 # To make this work, you probably need to go to "System Preferences /
15 # Security & Privacy / Privacy / Accessibility" and add "Terminal.app"
16 # to the list of allowed programs.
17 #
18 # Created: 18-Apr-2016.
19
20 function menu() {
21   which="$1"
22   sim="Simulator"
23  #proc="SystemUIServer"
24   proc="System Events"
25
26   osascript -e "
27    tell application \"$sim\" to activate
28    tell application \"$proc\"
29     tell process \"$sim\"
30      tell menu bar item \"Hardware\" of menu bar 1
31       click menu item \"$which\" of menu \"Hardware\"
32       \"$which\"
33      end tell
34     end tell
35    end tell"
36 }
37
38 menu 'Shake Gesture'
39
40 while true; do
41   i=$[ 2 + $[ RANDOM % 5 ]]
42   echo "sleep $i" ; sleep $i
43   i=$[ RANDOM % 5]
44   if [ $i == 0 ]; then menu 'Shake Gesture'
45   else
46     i=$[ RANDOM % 3]
47     if   [ $i == 0 ]; then menu 'Rotate Left'
48     elif [ $i == 1 ]; then menu 'Rotate Right'
49     else menu 'Rotate Right' ; menu 'Rotate Right'
50     fi
51   fi
52 done
53
54 exit 0