-
Notifications
You must be signed in to change notification settings - Fork 0
/
firefox-cmd-shift-n.applescript
49 lines (45 loc) · 2.11 KB
/
firefox-cmd-shift-n.applescript
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
tell application "System Events" # block prevents unecessary ffCloseOrder change on PIP
tell process "Firefox"
set x to 1
set focusedWIndex to 0
repeat with w in windows
if value of attribute "AXMain" of w is equal to true -- if focused of w is equal to true
set focusedWIndex to x
exit repeat
end if
set x to (x + 1)
end repeat
if count of windows > 0 and title of window focusedWIndex is equal to "Picture-In-Picture" then return "won't work on PIP"
end tell
end tell
tell application "BetterTouchTool"
trigger_named "ffReopenWindow"
set ffCloseOrder to get_string_variable "ffCloseOrder"
# pop last restore (w)indow
set_string_variable "ffCloseOrder" to my replaceLastInstanceOfChar(ffCloseOrder, "w", "")
end tell
to lastIndexOfChar(haystack, needle) # case insensitive
set ray to text items of haystack
set charCount to count of ray
set i to charCount
repeat charCount times
set cur_char to text item i of ray
if (cur_char is equal to needle) then exit repeat
set i to i - 1
end repeat
return i
end lastIndexOfChar
to replaceLastInstanceOfChar(haystack, needle, replaceWith)
set i to lastIndexOfChar(haystack, needle)
set charCount to count of haystack
if (i is equal to 0) then return haystack
if (i is equal to 1 and charCount is equal to 1) then return replaceWith
if (i is equal to 1) then return replaceWith & text (text item (i + 1)) thru (text item (-1)) of haystack # last instance = char 0
if (i is equal to charCount) then return text (text item 1) thru (text item (i - 1)) of haystack & replaceWith # last instance = last char
return text (text item 1) thru (text item (i - 1)) of haystack & replaceWith & text (text item (i + 1)) thru (text item (-1)) of haystack # last instance in the middle
end replaceLastInstanceOfChar
# replace first instance of needle
-- to str_replace(haystack, needle, replaceWith)
-- set AppleScript's text item delimiters to needle
-- return text item 1 of haystack & replaceWith & text (text item 2) thru (text item -1) of haystack
-- end str_replace