Skip to content

Commit

Permalink
Add a first version
Browse files Browse the repository at this point in the history
  • Loading branch information
lucapette committed Jan 30, 2017
1 parent f3ce6a1 commit 15fd9d2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ _testmain.go
*.exe
*.test
*.prof
t
52 changes: 52 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"bytes"
"log"
"os"
"os/exec"
"os/signal"
"time"
)

var script = `
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
set activeURL to ""
if frontApp is "Google Chrome" then
tell application "Google Chrome"
set normalWindows to (windows whose mode is not "incognito")
if length of normalWindows is greater than 0 then
set activeURL to (get URL of active tab of (first item of normalWindows))
end if
end tell
end if
end tell
frontApp & "," & (activeURL) as String
`

func run() string {
cmd := exec.Command("osascript", "-")
cmd.Stdin = bytes.NewBufferString(script)
output, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
return string(output)
}

func main() {
go func() {
c := time.Tick(1 * time.Second)
for range c {
log.Printf(run())
}
}()

s := make(chan os.Signal, 1)
signal.Notify(s, os.Interrupt, os.Kill)
<-s
}

0 comments on commit 15fd9d2

Please sign in to comment.