aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript
blob: e6b64cfb0648707d31373b87b4707873b4fdf595 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
set browser to ""
set title_string to ""
set active_tab to 0

to replace_chars(this_text, search_string, replacement_string)
 set AppleScript's text item delimiters to the search_string
 set the item_list to every text item of this_text
 set AppleScript's text item delimiters to the replacement_string
 set this_text to the item_list as string
 set AppleScript's text item delimiters to ""
 return this_text
end replace_chars

try
  do shell script "osascript -e 'id of application \"Google Chrome\"'"
  if application "Google Chrome" is running then
    tell application "Google Chrome"
      set window_list to every window

      repeat with the_window in window_list
        set tab_list to every tab in the_window

        repeat with the_tab in tab_list
          set the_title to the title of the_tab
          set the_url to the URL of the_tab
          if "- YouTube" is in the_title then
            if active_tab is 0 then set title_string to " " & text 1 thru -11 of the_title
            set browser to "chrome"
            set active_tab to 1
          end if
          if "open.spotify.com" is in the_url then
						if active_tab is 0 then set title_string to " " & text of the_title
						set browser to "chrome"
						set active_tab to 1
						if "Spotify" is in the_title then set title_string to ""
					end if
        end repeat
      end repeat
    end tell
  end if
end try

try
	do shell script "osascript -e 'id of application \"Brave Browser\"'"
	if application "Brave Browser" is running then
		tell application "Brave Browser"
			set window_list to every window
			
			repeat with the_window in window_list
				set tab_list to every tab in the_window
				
				repeat with the_tab in tab_list
					set the_url to the URL of the_tab
					set the_title to the title of the_tab
          if "- YouTube" is in the_title then
            if active_tab is 0 then set title_string to " " & text 1 thru -11 of the_title
            set browser to "brave"
            set active_tab to 1
          end if
					if "open.spotify.com" is in the_url then
						if active_tab is 0 then set title_string to " " & text of the_title
						set browser to "brave"
						set active_tab to 1
						if "Spotify" is in the_title then set title_string to ""
					end if
				end repeat
			end repeat
		end tell
	end if
end try

if application "Safari" is running then
  tell application "Safari"
    set window_list to every window

    repeat with the_window in window_list
      set tab_list to every tab in the_window

      repeat with the_tab in tab_list
        set the_title to the name of the_tab
        if "- YouTube" is in the_title then
          if active_tab is 0 then set title_string to " " & text 1 thru -11 of the_title
          set browser to "safari"
          set active_tab to 1
        end if
      end repeat
    end repeat
  end tell
end if

return "{ \"browser\": \"" & browser & "\", \"title\": \"" & replace_chars(title_string, "\"", "Ò") & "\" }"