I’m trying to get Safari to loop indefinitely through a bunch of URLs until the mouse button is pressed.
I’ve gotten the script to loop, with a delay, through the URLs, but I want it to be easy for someone to quit the script. Ideally, I would like something where when the mouse is clicked, a dialog box pops up and asks them if they want to quit, with the option of continuing and the option of completely quitting the script.
This is my first applescript, and I’ve spent all day trying to figure out how to read a mouse click, and then act on it. I’m sure this information is on the site, but truthfully, I can’t find it.
i think your looking at a scripting extension to solve this for you on the mouse click front.
Adam has posted a link to something you might find helpfull here!
if you wanted to go the dialog route you could do somthing like this
set x to 1
repeat 100 times
if x is 10 then
if button returned of (display dialog "would you like to quit?" buttons {"Quit"} giving up after 5) is not "" then exit repeat
set x to 1
else
set x to x + 1
end if
end repeat
Another solution might be to use something as a flag for bringing up a dialog. For instance, the following brings up the dialog when Safari is not the frontmost process:
tell application "Safari" to activate
repeat
tell application "Safari"
-- do whatever
end tell
tell application "Finder"
set front_proc to name of first process whose frontmost is true
end tell
if front_proc is not "Safari" then
try
tell application (path to frontmost application as string)
display dialog "Do you want to quit?"
end tell
return
on error
tell application "Safari" to activate
end try
end if
do shell script "sleep 2"
end repeat
The user could quit by clicking on the desktop or running another app. Instead of using a repeat loop, it would be better to use an idle handler.