Last active
December 20, 2015 09:19
-
-
Save stisti/6106560 to your computer and use it in GitHub Desktop.
Someone asked on Twitter how to refresh Safari window until a text is found. I thought that must be simple. Well, it still took me about an hour to put this together.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Safari" | |
activate | |
try | |
set urlForPolling to URL of front document | |
set tabForPolling to current tab of front window | |
on error | |
display dialog "Please open some web page first" with title "Error" with icon stop buttons {"OK"} default button 1 | |
return | |
end try | |
display dialog "Reload the active page until a text is found." & return & "Enter the text to look for" with title "Safari reloader" default answer "" | |
set needle to text returned of the result | |
repeat | |
set haystack to text of tabForPolling | |
if haystack contains needle then | |
say "Text was found on the page" | |
exit repeat | |
end if | |
delay 3 | |
set URL of tabForPolling to urlForPolling | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment