Run a function in the background?

Anyone know how to run a function in the background without the application be completely inactive for the user?

If the function is in a button click the function runs fine in the background and the application is still usable.

However, I’m trying to run a repeating function on start of my application, but when I do this the whole application becomes inactive. I have tried awake from nib and on finished launching…etc., but I still get the same results. Is there a way around this?

Thank you!

2 ideas:

  1. you need threading so that function works on one thread while the main application functions on another. I don’t know how to do this by the way. If you figure it out post it.

  2. Why not make that background function an actual separate application from your main application? Like a faceless background app or a shell script or an applescript? Then your main app can launch the background app where it can do it’s thing. Then you have to figure how to pass information from it back to the main app if needed. so maybe you can write the info to file then read in the file to your main app. I’ve never done this either but it seems that would work.

regulus6633, thank you for the post. Yeah, I tried a a shell script and a separate AppleScript, but what I am trying to do is not working. If user default runVar = true then run function at start of app. This will work if I put the function in “on idle” and my app will be active for the user. However, I will have to write a bit more code to handle the on idle call if the runVar is read in as false.


I think you might be able to use ignoring:

		ignoring application responses
			do shell script "/path/to/script"
		end ignoring