-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.go
More file actions
38 lines (31 loc) · 835 Bytes
/
Copy pathscript.go
File metadata and controls
38 lines (31 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package tracker
import (
"bytes"
"os/exec"
"strings"
)
const 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
if activeURL is not "" then
activeURL
else
frontApp
end if
`
func GetActivityName() (string, error) {
cmd := exec.Command("osascript", "-")
cmd.Stdin = bytes.NewBufferString(script)
output, err := cmd.Output()
return strings.Replace(string(output), "\n", "", -1), err
}