I like to download challenging scripts and try to figure out how they work and this one is really different. I copied the script from Bastiaan Boertien submitted on 10/31/10. I’ve tried for several days but I can’t get it to run right on my machine (iMac mid-2011, Mac OS X 10.6.8), either in AppleScript Editor or from a saved application on the desktop.
on cancelDialog() display dialog "Process is canceled" end cancelDialog on backgroundScript() script prototype property __forkID : missing value property __callBack : missing value property __applescriptCode : missing value on __construct() set __forkID to null set __callBack to null set __applescriptCode to null end __construct on setApplescriptCode(applescriptCode) set __applescriptCode to applescriptCode end setApplescriptCode on setCallBack(callBack) set __callBack to callBack end setCallBack on startFork() set theCommand to "osascript -e" & quoted form of __applescriptCode & " > /dev/null 2> /dev/null & echo $!" set __forkID to (do shell script theCommand) end startFork on stopFork() do shell script ("kill " & __forkID & " > /dev/null 2> /dev/null" as string) __callBack() end stopFork end script __construct() of prototype return prototype end backgroundScript set a to backgroundScript() setApplescriptCode("repeat tell application \"finder\" to display dialog \"Hello World!\" end repeat") of a setCallBack(cancelDialog) of a startFork() of a delay 5 stopFork() of a
Here are the problems that I have had:
When I double click on the application, the Finder icon in the Dock bounces and a few seconds later the “Process is canceled” dialog window appears (at this point I move the dialog so I can see the other dialog if it appears). Icon continues to bounce (probably forever).
(1) If I click on the Finder desktop the bouncing icon stops, the Cancel dialog is still present, and the Hello dialog appears (so at this point both dialogs are on the screen).
(a) If I click on either the Cancel or OK buttons of the Hello dialog, the Hello dialog goes away and the Cancel dialog remains on the screen. If I click on either the Cancel or the OK button of the Cancel dialog the program quits.
(b) If I click on either the Cancel or OK buttons of the Cancel dialog, the Cancel dialog goes away and the Hello dialog remains on the screen. If I click on either the Cancel or the OK button of the Cancel dialog the program quits.
(2) If instead of clicking on the desktop I click on the Finder icon in the Dock everything happens as described in (1) above.
(3) In fact I discovered that if I simply hover the mouse over the icon in the Dock it does the same as in (1) above. I was very surprised at this because I have never seen it happen with any other of my programs (is this normal behavior for the Finder ?).
When I run the script from AppleScript Editor the Finder icon bounces and the Cancel dialog appears after a few seconds. If I dismiss the Cancel dialog by clicking either button the Finder icon continues to bounce. If I then click on the Finder desktop the Hello dialog appears. In other words with this way of running the program I have never gotten both dialogs on the screen at the same time (as above the order of appearance is reversed).
I would like to get this script to work just on general principals and it’s possible that I could use this method in some of my own scripts.
So my questions would be:
Is the script not compatible with 10.6.8 or is there a problem with timing on the latest iMac compared to older machines? If this is the case I will give up.
I would welcome any suggestions as to how I can change the script to get it to work or to find out where the problem is? I will try any suggestions, but I should say that I consider myself a rank beginner at debugging programs.
Model: iMac 2011
Browser: Safari 533.21.1
Operating System: Mac OS X (10.6)