Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to execute a script when a server becomes available (a bit like when the OS detect the presence of a time capsule device and it starts the backup.) I didn't find a simple way to attach an applescript to an system event. Is there a way?

I am not looking for anything that requires a compiler. I am simply looking at attaching to an OS event (a bit like "Folder Actions" I guess, but for a server.)

share|improve this question

migrated from Jun 21 '11 at 12:52

This question came from our site for professional and enthusiast programmers.

Cross-posted to SU. – Nathan Greenstein Jun 21 '11 at 13:27
up vote 1 down vote accepted

The only way I can think of is run an script with an idle handler that periodically checks to see if the server is available and if so executes another script or another portion of the same script.

share|improve this answer
since i didn't get any better answer, this is a work around I will accept as an answer. – machunter Jul 3 '11 at 8:05

You can use launchd for that purpose. Here is an example of a launchd config plist that will execute an AppleScript when a disk is mounted:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

To activate the config plist save it to the LaunchAgents folder in your Library folder as Example.plist.

From the Terminal you can then use the command launchctl to activate Example.plist by running:

launchctl load ~/Library/LaunchAgents/Example.plist

The AppleScript will then be run each time a filesystem is mounted.

To deactivate it, run:

launchctl unload ~/Library/LaunchAgents/Example.plist
share|improve this answer
I guess this answers my question partially. The StartOnMount option specifies the script to run when a disk is mounted. What I really want is my script to launch when a server is available on the network. I will look into launchd's man pages see if there is anything I can use. – machunter Jun 19 '11 at 19:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.