When an application appears to work, but doesn’t seem to be matching its conditions, it is always helpful to look at the actual values being checked. In this case, open the URL you think should be matched, and then get that URL to look at.
tell application "Google Chrome"
get URL of tab 1 of window 1
end tell
When I entered “Facebook.com” in a new window in Chrome, and then ran the above script, what I found was https://www.facebook.com/?_rdr=p
.
When I replaced “Facebook.com” in your code sample with https://www.facebook.com/?_rdr=p
, the script now had an affect; it redirected to Chrome’s about page.
Taking a cue from the necessity of using the full URL in the condition, I switched “twitter.com” to “http://twitter.com/”.
The script now performs as I understand you intended it to: every tab in every window that matches https://www.facebook.com/?_rdr=p
gets redirected to twitter.com.
repeat until application "Google Chrome" is not running
if application "Google Chrome" is running then
tell application "Google Chrome"
set (URL of every tab of every window where URL is equal to "https://www.facebook.com/?_rdr=p") to "http://twitter.com/"
end tell
end if
end repeat
Applescript and Google Chrome are matching your conditional’s text against the full URL, so your conditional has to use the full URL as well.
@vadian’s note about using an idle handler is a very good one. See this Hourly Pop-up Alert question for ideas on using an idle handler. Something like this should work:
on idle
if application "Google Chrome" is running then
tell application "Google Chrome"
set (URL of every tab of every window where URL is equal to "https://www.facebook.com/?_rdr=p") to "http://twitter.com/"
end tell
end if
--number of seconds to wait for the next check
return 1
end idle
Save as application, stay open after run handler.