Last active
August 29, 2015 14:14
-
-
Save dorajistyle/2c4f5830a96286a24a4b to your computer and use it in GitHub Desktop.
X11 quick window activation between web browser and editor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# X11 quick window activation between web browser and editor. | |
# This script requires (http://www.semicomplete.com/projects/xdotool/) | |
# Toggling between web browser and editor, just put 'toggle_window.sh' into your keyboard shortcut. | |
# When you want to show up Development tool window, put 'toggle_window.sh devtool' into your keyboard shortcut. | |
# Improvements are welcome | |
# Public Domain, JoongSeob Vito Kim, 2015 | |
activate_name=$(xdotool getactivewindow) | |
browser_name="" | |
# This example use 'atom' editor but you can use any kind of editor(vim,emacs,sublimetext...), IDE(Eclipse,Jetbrain...) or others. | |
editor_name=$(xdotool search --name 'atom' | tail -1) | |
editor_name_length=${#editor_name} | |
if (( $editor_name_length == 0 )); then | |
editor_name=$(xdotool search --name 'focuswriter' | tail -1) | |
fi | |
# This example use 'chrome' browser but you can use any kind of browser. | |
dev_tool_name=$(xdotool search --name 'Developer Tools' | tail -1) | |
browser_names=$(xdotool search --name 'chrome') | |
if [[ $1 == "devtool" ]] | |
then | |
xdotool windowactivate $dev_tool_name | |
else | |
while read line; do | |
# Please check your browser window's geometry and replace 1920x1080 to yours. | |
browser_name_temp=$(xdotool getwindowgeometry $line | grep 1920x1080) | |
length=${#browser_name_temp} | |
if (( $length > 0 )); then | |
browser_name=$line | |
fi | |
done <<<"$browser_names" | |
echo "browser name = $browser_name" | |
if test "$activate_name" == "$browser_name"; then | |
echo $editor_name | |
xdotool windowactivate $editor_name | |
else | |
echo $browser_name | |
xdotool windowactivate $browser_name | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment