-
Notifications
You must be signed in to change notification settings - Fork 0
/
reload-chrome.scpt
56 lines (47 loc) · 1.62 KB
/
reload-chrome.scpt
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
-- AppleScript to make Chrome reload every tab that matches a base URL.
on run {targetUrl}
tell application "Google Chrome"
-- activate
set theUrl to my remove_http(targetUrl)
if (count every window) = 0 then
make new window
end if
set found to false
set theTabIndex to -1
repeat with theWindow in every window
set theTabIndex to 0
repeat with theTab in every tab of theWindow
set theTabIndex to theTabIndex + 1
set theTabUrl to my remove_http(theTab's URL as string)
if (theTabUrl contains theUrl) then
set found to true
tell theTab to reload
set theWindow's active tab index to theTabIndex
set index of theWindow to 1
end if
end repeat
end repeat
end tell
end run
on remove_http(input_url)
if (input_url contains "https://") then
return trim_line(input_url, "https://")
else
return trim_line(input_url, "http://")
end if
return input_url
end remove_http
-- Taken from: http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html --
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
-- TRIM BEGINNING
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
return this_text
end trim_line