aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript')
-rwxr-xr-xusers/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript91
1 files changed, 91 insertions, 0 deletions
diff --git a/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript b/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript
new file mode 100755
index 0000000..e6b64cf
--- /dev/null
+++ b/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/browser-audio.applescript
@@ -0,0 +1,91 @@
1set browser to ""
2set title_string to ""
3set active_tab to 0
4
5to replace_chars(this_text, search_string, replacement_string)
6 set AppleScript's text item delimiters to the search_string
7 set the item_list to every text item of this_text
8 set AppleScript's text item delimiters to the replacement_string
9 set this_text to the item_list as string
10 set AppleScript's text item delimiters to ""
11 return this_text
12end replace_chars
13
14try
15 do shell script "osascript -e 'id of application \"Google Chrome\"'"
16 if application "Google Chrome" is running then
17 tell application "Google Chrome"
18 set window_list to every window
19
20 repeat with the_window in window_list
21 set tab_list to every tab in the_window
22
23 repeat with the_tab in tab_list
24 set the_title to the title of the_tab
25 set the_url to the URL of the_tab
26 if "- YouTube" is in the_title then
27 if active_tab is 0 then set title_string to " " & text 1 thru -11 of the_title
28 set browser to "chrome"
29 set active_tab to 1
30 end if
31 if "open.spotify.com" is in the_url then
32 if active_tab is 0 then set title_string to " " & text of the_title
33 set browser to "chrome"
34 set active_tab to 1
35 if "Spotify" is in the_title then set title_string to ""
36 end if
37 end repeat
38 end repeat
39 end tell
40 end if
41end try
42
43try
44 do shell script "osascript -e 'id of application \"Brave Browser\"'"
45 if application "Brave Browser" is running then
46 tell application "Brave Browser"
47 set window_list to every window
48
49 repeat with the_window in window_list
50 set tab_list to every tab in the_window
51
52 repeat with the_tab in tab_list
53 set the_url to the URL of the_tab
54 set the_title to the title of the_tab
55 if "- YouTube" is in the_title then
56 if active_tab is 0 then set title_string to " " & text 1 thru -11 of the_title
57 set browser to "brave"
58 set active_tab to 1
59 end if
60 if "open.spotify.com" is in the_url then
61 if active_tab is 0 then set title_string to " " & text of the_title
62 set browser to "brave"
63 set active_tab to 1
64 if "Spotify" is in the_title then set title_string to ""
65 end if
66 end repeat
67 end repeat
68 end tell
69 end if
70end try
71
72if application "Safari" is running then
73 tell application "Safari"
74 set window_list to every window
75
76 repeat with the_window in window_list
77 set tab_list to every tab in the_window
78
79 repeat with the_tab in tab_list
80 set the_title to the name of the_tab
81 if "- YouTube" is in the_title then
82 if active_tab is 0 then set title_string to " " & text 1 thru -11 of the_title
83 set browser to "safari"
84 set active_tab to 1
85 end if
86 end repeat
87 end repeat
88 end tell
89end if
90
91return "{ \"browser\": \"" & browser & "\", \"title\": \"" & replace_chars(title_string, "\"", "Ò") & "\" }"