Rotate Beryl/Compiz cube from command line
We are about to have a stand in a show in Israel. To pull some attention, I have searched for a method to automate a random rotation of the famous Beryl/Compiz cube.
An extension of the method provided in here (using macros) is demonstrated below, using a script.
This is a bit more complicated, as I have used the motions of the mouse to achieve a “show” out of it (just changing desktops isn’t enough nowadays…)
Check out below for the full script.
#!/bin/bash
# This script will rotate the cube one click on each direction each predefined
# timer.
# Written by ezaton at tournament.org.il
# Check out my technical blog “Running Systems” at http://www.tournmament.org.il/run# Set timer (seconds)
TIMER=10
VERT_TIMER=1# Possible directions? 4 (up, down, left, right. will be marked from 0 to 3)
# Addition – set it to give higher priority to side-stepping. So max is 10, and only 0&1 represent
# up/down
# Added 10 to represent 2xleft and 11 to represent 2xright
POSS=12# Temp command file
TMP_FILE=/tmp/rotate.macrofunction create_file {
# This function will create and secure the macro file
rm $TMP_FILE
if [ -f $TMP_FILE ]; then
echo “$TMP_FILE still exists”
exit 1
fi
echo “” > $TMP_FILE
chmod 700 $TMP_FILE
}function run_macro {
# Run the actual macro
cat $TMP_FILE | xmacroplay $DISPLAY &>/dev/null
}function left {
# This function will build the macro file for the “left” command
echo > $TMP_FILE
echo “MotionNotify 100 380” >> $TMP_FILE
echo “KeyStrPress Alt_L” >> $TMP_FILE
echo “KeyStrPress Control_L” >> $TMP_FILE
echo “ButtonPress 1” >> $TMP_FILE
echo “MotionNotify 100 380” >> $TMP_FILE
echo “MotionNotify 130 380” >> $TMP_FILE
echo “MotionNotify 150 380” >> $TMP_FILE
echo “MotionNotify 170 380” >> $TMP_FILE
echo “MotionNotify 190 380” >> $TMP_FILE
echo “MotionNotify 210 380” >> $TMP_FILE
echo “MotionNotify 230 380” >> $TMP_FILE
echo “MotionNotify 250 380” >> $TMP_FILE
echo “MotionNotify 270 380” >> $TMP_FILE
echo “MotionNotify 290 380” >> $TMP_FILE
echo “MotionNotify 310 380” >> $TMP_FILE
echo “MotionNotify 330 380” >> $TMP_FILE
echo “ButtonRelease 1” >> $TMP_FILE
echo “KeyStrRelease Control_L” >> $TMP_FILE
echo “KeyStrRelease Alt_L” >> $TMP_FILE
run_macro
}function up {
# This function will build the macro file for the “up” command
echo > $TMP_FILE
echo “MotionNotify 100 100” >> $TMP_FILE
echo “KeyStrPress Alt_L” >> $TMP_FILE
echo “KeyStrPress Control_L” >> $TMP_FILE
echo “ButtonPress 1” >> $TMP_FILE
echo “MotionNotify 100 100” >> $TMP_FILE
echo “MotionNotify 100 120” >> $TMP_FILE
echo “MotionNotify 100 140” >> $TMP_FILE
echo “MotionNotify 100 160” >> $TMP_FILE
echo “MotionNotify 100 180” >> $TMP_FILE
echo “MotionNotify 100 200” >> $TMP_FILE
echo “MotionNotify 100 220” >> $TMP_FILE
echo “MotionNotify 100 240” >> $TMP_FILE
echo “MotionNotify 100 260” >> $TMP_FILE
echo “MotionNotify 100 280” >> $TMP_FILE
echo “MotionNotify 100 300” >> $TMP_FILE
echo “MotionNotify 100 320” >> $TMP_FILE
echo “ButtonRelease 1” >> $TMP_FILE
echo “KeyStrRelease Control_L” >> $TMP_FILE
echo “KeyStrRelease Alt_L” >> $TMP_FILE
run_macro
}function right {
# This function will build the macro file for the “right” command
echo > $TMP_FILE
echo “MotionNotify 340 380” >> $TMP_FILE
echo “KeyStrPress Alt_L” >> $TMP_FILE
echo “KeyStrPress Control_L” >> $TMP_FILE
echo “ButtonPress 1” >> $TMP_FILE
echo “MotionNotify 340 380” >> $TMP_FILE
echo “MotionNotify 320 380” >> $TMP_FILE
echo “MotionNotify 300 380” >> $TMP_FILE
echo “MotionNotify 280 380” >> $TMP_FILE
echo “MotionNotify 260 380” >> $TMP_FILE
echo “MotionNotify 240 380” >> $TMP_FILE
echo “MotionNotify 220 380” >> $TMP_FILE
echo “MotionNotify 200 380” >> $TMP_FILE
echo “MotionNotify 180 380” >> $TMP_FILE
echo “MotionNotify 160 380” >> $TMP_FILE
echo “MotionNotify 140 380” >> $TMP_FILE
echo “MotionNotify 120 380” >> $TMP_FILE
echo “ButtonRelease 1” >> $TMP_FILE
echo “KeyStrRelease Control_L” >> $TMP_FILE
echo “KeyStrRelease Alt_L” >> $TMP_FILE
run_macro
}function down {
# This function will build the macro file for the “down” command
echo > $TMP_FILE
echo “MotionNotify 100 330” >> $TMP_FILE
echo “KeyStrPress Alt_L” >> $TMP_FILE
echo “KeyStrPress Control_L” >> $TMP_FILE
echo “ButtonPress 1” >> $TMP_FILE
echo “MotionNotify 100 330” >> $TMP_FILE
echo “MotionNotify 100 310” >> $TMP_FILE
echo “MotionNotify 100 290” >> $TMP_FILE
echo “MotionNotify 100 270” >> $TMP_FILE
echo “MotionNotify 100 250” >> $TMP_FILE
echo “MotionNotify 100 230” >> $TMP_FILE
echo “MotionNotify 100 210” >> $TMP_FILE
echo “MotionNotify 100 190” >> $TMP_FILE
echo “MotionNotify 100 170” >> $TMP_FILE
echo “MotionNotify 100 150” >> $TMP_FILE
echo “MotionNotify 100 130” >> $TMP_FILE
echo “MotionNotify 100 110” >> $TMP_FILE
echo “ButtonRelease 1” >> $TMP_FILE
echo “KeyStrRelease Control_L” >> $TMP_FILE
echo “KeyStrRelease Alt_L” >> $TMP_FILE
run_macro
}function fix_vert {
# Fixes a case of vertical extention (non-viewable screen)
sleep $VERT_TIMER
case “$1” in
1) down
;;
0) up
;;
esac
}# Verify we have xmacroplay
which xmacroplay
if [ “$?” -ne “0” ]; then
echo “Missing xmacroplay. Install it”
echo “Use apt get install xmacro”
exit 1
fi# Do we use X and have a defined display? Won’t work otherwise…
if [ -z “$DISPLAY” ]; then
echo “DISPLAY is not defined. Exiting”
exit 1
ficreate_file
# We start where all is viewable
while true; do
# Select direction
DIRECTION=$RANDOM
let “DIRECTION %= $POSS”
# Debug: echo “*** $DIRECTION ***”
case “$DIRECTION” in
0) up
fix_vert 1
;;
1) down
fix_vert 0
;;
[2-5]) left
;;
[6-9]) right
;;
10) left
left
;;
11) right
right
;;
esac
sleep $TIMER
doneexit 0