tags:

views:

48

answers:

1

I have an applescript that does something similar to:

using terms from application "iChat"
  on logout finished
    delay 30
    … do some stuff
  end logout finished
end using terms from

The problem with this script, is that it also blocks the application calling it for the 30 seconds. What I would like to do then is say something like "in thirty seconds, please run this script for me", and then move all of my … do some stuff to that other script. But I can't see how to do that?

Any suggestions?

+1  A: 

Since you are using a Mac, I assume you have Ruby installed.

What you are talking about sounds like you want a thread to sleep for 30 seconds and then execute a script in the background.

You should put … do some stuff in a script named dostuff.scpt and place it in your Desktop.

Then change your current script to the following code:

using terms from application "iChat"
 on logout finished
  do shell script "ruby -e 'Thread.new {`sleep 30 && osascript ~/Desktop/dostuff.scpt`}' &> /dev/null"
 end logout finished
end using terms from

A code breakdown: do shell script (executes something from the command line)

ruby -e (executes ruby code from the command line)

Thread.new (makes a new thread to hide in the background)

` (Everything in the backtick is a shell command in ruby)

osascript (Executes an applescript from the command line)

~/Desktop/dostuff.scpt (Points the pathname to your file, the tilde substitutes to your home directory, and I assume you put dostuff.scpt on the Desktop)

&> /dev/null (Tells Applescript to not look for output and immediately go to the next code line)

I tried doing this without Ruby, however, I had no luck. Let me know if this works for you!

Sebastian Gallese
Yes, that did the trick… Thanks!
Paul Wagland
has