Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created May 22, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OKsign/b8e17f9b64508f788e03ab747aaf4187 to your computer and use it in GitHub Desktop.
Save OKsign/b8e17f9b64508f788e03ab747aaf4187 to your computer and use it in GitHub Desktop.
try
tell application "Firefox"
activate
end tell
delay 1
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
repeat 300 times
tell application "Firefox"
activate
end tell
if activeApp is "Firefox" then
exit repeat
end if
end repeat
end tell
tell application "System Events"
keystroke "a" using command down
delay 0.2
keystroke "c" using command down
delay 0.7
set shortcut to the clipboard
delay 0.5
set sTerm to "123456"
keystroke sTerm
delay 1
key code 36
delay 2
end tell
tell application "System Events"
repeat 200 times
keystroke "l" using command down
delay 0.2
keystroke "a" using command down
delay 0.2
keystroke "c" using command down
delay 0.7
set wURL2 to the clipboard
if wURL2 contains sTerm then
delay 0.02
try
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the sTerm -- search
set the item_list to every text item of wURL2 -- original text
delay 0.04
set AppleScript's text item delimiters to the "%s" -- replace
set pattern to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end try
exit repeat
end if
end repeat
end tell
tell application "System Events"
key code 53
delay 0.03
tell application "Firefox"
set winName to get name of window 1
delay 0.02
set siteName to winName
if winName contains "- " then
set AppleScript's text item delimiters to {"- "}
set siteName to last text item of winName
end if
if winName contains "| " then
set AppleScript's text item delimiters to {"| "}
set siteName to last text item of winName
end if
if siteName contains "– " then
set AppleScript's text item delimiters to {"– "}
set siteName to last text item of winName
end if
end tell
delay 0.2
keystroke "d" using command down
delay 1
keystroke "Search " & siteName
delay 0.05
keystroke "a" using command down
delay 0.2
keystroke "c" using command down
delay 0.7
set bookName to the clipboard
key code 36
delay 0.2
keystroke "b" using {command down, shift down}
delay 0.2
tell application "Firefox"
activate
delay 1
repeat 300 times
tell application "Firefox"
activate
set winName to get name of window 1
if winName is "Library" then
exit repeat
end if
end tell
end repeat
end tell
keystroke "f" using command down
delay 0.2
keystroke bookName
delay 0.2
repeat 7 times
delay 0.02
key code 48
end repeat
key code 49
delay 0.2
keystroke "f" using command down
delay 0.03
key code 124
delay 0.03
repeat 4 times
delay 0.02
key code 48
end repeat
delay 0.02
keystroke pattern
delay 0.7
repeat 3 times
delay 0.02
key code 48
end repeat
delay 0.02
keystroke shortcut
delay 1
keystroke "w" using command down
delay 1.5
display notification "Done!" with title "Script 10.1"
end tell
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment