I have a script that mounts a specific set of volumes. It works perfectly well when manually run in the finder.
However, when I make it one of the startup items, it times out without mounting the servers.
(Don’t ask why I want to mount these volumes with a script. There is a good reason relating to LDAP integration between Solaris and OSX Server.)
What my gut told me was that the script was trying to mount the servers prior to network services fully initializing. So, I tried putting a delay in the beginning of the script. That didn’t work. I tried showing a dialog, giving up after x time. That didn’t work. Finally, I start the script with having the finder launch TextEdit, and that seems to work.
This is obviously kind of a clunky and awkward workaround to the problem. Does anyone know of a more elegant way to solve this problem?
To reiterate, the script is indeed launching. You can see that the applescript app icon is already visible when the dock appears, but it just hangs and eventually the apple event times out. However, if I have the script launch TextEdit prior to attempting to mount the volumes, then the script works successfully. (Yet, putting a delay in the beginning of the script does NOT work either.)
My guess about what is happening is this: The script begins very early in the boot process while other background processes are completing. It attempts to mount the volumes before network processes are fully initialize. The script seems to be taking priority over the network initialization process, so that process waits until the script completes it’s tasks. This puts the computer in a catch 22. The network initialization process is waiting on the script, and the script can’t complete without the network being fully initialized.
Applescript seems to be more patient with a task such as launching an application. So it (or the OS) waits a little longer into the boot process before attempting to execute that task. So by the time the script attempts to mount the volumes, the network is fully initialized and executes successfully.
Opening and then quitting TextEdit seems to be a crude solution. I was wondering if anyone can think of a more elegant workaround to this problem. I’m relatively new to applescript, and have kind of hit a wall.
One idea I had was to use the repeat loop:
repeat until (condition is true)
– do something
end repeat
However, I have have no idea what condition to test for, nor what to have it do while it is waiting for it to be true.
you know, the few times I’ve tried to do applescripts at startup time they always behaved funky. that was back under OS9, and I assumed they’d fixed that in X. guess not…
a few things you can try, with no promises.
try writing a script that calls and runs the volume mounting script from a different file (using the Load Script and Run Script from standard additions). I got an explanation from someone once (one that I couldn’t quite follow) about how using nested scripts like that that changes the runtime environment somehow. mathomagica…
try a delay loop. something like (off the cuff):
set volumes_mounted to true
repeat while volumes_mounted is false
tell application “Finder”
if alias exists then set volumes_mounted to true
return (or exit repeat)
end tell
delay 3
end repeat
the delay command lets the computer run off and do other stuff for 3 seconds, and then come back and try the mounting thing again.
try an idle loop. this is a little different conceptually - you’ll have to structure the script as a stay-open application (which means you’ll have to have it tell itself to quit after your volumes are mounted), and it will be an actual sub-routine in its own right (on idle()…), but it will do essentially the same thing as (2) - give the processor time to work on other stuff while it’s waiting for the volumes to mount.