Hack and / - Lightning Hacks Strike Twice
My laptop doubles as a tablet, and even though I don't use the tablet mode very often, when I do use it, I like to be able to rotate the screen around to portrait mode and back. Now, dock applications exist that can do this with a few clicks, and I always could just try to remember the right xrandr commands, but instead, I wrote a little script that I then bound to one of the hardware buttons on my laptop display. Each time I press the button, it runs the script and rotates the screen another 90 degrees.
The key to the script is to keep track of your current orientation. When xrandr rotates, it rotates only left, right, inverted or normal, so if you already are rotated to the left and rotate left again, it won't change. To accomplish this, I just write the current orientation to a temporary file. Listing 1 shows the full script.
Listing 1. Screen Rotation Script
#!/bin/sh export ORIENTATION=`cat /tmp/.orientation` if [ $ORIENTATION -eq "90" ]; then xrandr --auto xrandr --output LVDS --rotate inverted echo 180 > /tmp/.orientation echo "180" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & elif [ $ORIENTATION -eq "180" ]; then xrandr --auto xrandr --output LVDS --rotate left echo 270 > /tmp/.orientation echo "270" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & elif [ $ORIENTATION -eq "270" ]; then xrandr --output LVDS --rotate normal echo "Normal" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & echo 0 > /tmp/.orientation else xrandr --auto xrandr --output LVDS --rotate right echo 90 > /tmp/.orientation echo "90" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & fi
Notice in Listing 1 that I also added an echo piped to osd_cat. This is optional and just displays the current orientation on my screen. If you want to use this, be sure you have the osd_cat utility (it's included with the xosd-bin package in Debian and Ubuntu). The way the script is set up, it will run through each of the orientations in order before it goes back to normal. Because the temporary file will be deleted any time the machine reboots, I made sure to set the default mode to rotate 90 degrees.
Kyle Rankin is a Senior Systems Administrator in the San Francisco Bay Area and the author of a number of books, including Knoppix Hacks and Ubuntu Hacks for O'Reilly Media. He is currently the president of the North Bay Linux Users' Group.
Kyle Rankin is a VP of engineering operations at Final, Inc., the author of a number of books including DevOps Troubleshooting and The Official Ubuntu Server Book, and is a columnist for Linux Journal. Follow him @kylerankin.
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Bitcoin on Amazon! Sort of...
- The Tiny Internet Project, Part I
- Android Browser Security--What You Haven't Been Told
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Nativ Disc
- Returning Values from Bash Functions
- Epiq Solutions' Sidekiq M.2
- Securing the Programmer
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide