-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
t |
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
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 | ||
} |