Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
78 lines (60 sloc) 1.28 KB
package main
import (
"fmt"
"os"
"os/exec"
"regexp"
)
func main() {
windowName := getWindowName(getActiveWindow())
for _, value := range getMap() {
match, _ := regexp.MatchString(value[0], windowName)
if match {
if value[1] != "" {
typeIntoActive(value[1])
}
if value[2] != "" {
if value[1] != "" {
keyIntoActive("Tab")
}
typeIntoActive(value[2])
}
keyIntoActive("Return")
break
}
}
}
func getActiveWindow() string {
cmd := exec.Command("xdotool", "getwindowfocus")
var stdout, err = cmd.Output()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return string(stdout)
}
func getWindowName(id string) string {
cmd := exec.Command("xdotool", "getwindowname", id)
var stdout, err = cmd.Output()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return string(stdout[:len(stdout)-1])
}
func typeIntoActive(what string) {
cmd := exec.Command("xdotool", "sleep", "0.25", "type", "--clearmodifiers", what)
var _, err = cmd.Output()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func keyIntoActive(what string) {
cmd := exec.Command("xdotool", "sleep", "0.25", "key", "--clearmodifiers", what)
var _, err = cmd.Output()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}