Go Back   The macosxhints Forums > OS X Help Requests > Applications



Reply
 
Thread Tools Rate Thread Display Modes
Old 09-30-2008, 03:34 PM   #1
daftcain
Registered User
 
Join Date: Sep 2008
Posts: 2
launch a program when idle, quit the program when not

Hello all,

I am trying to find a way to have a specific program launch when the machine becomes idle (not when it goes to sleep), and then quits or the process is killed once the machine is not idle anymore. After looking around here it seems that a program called Senario (http://www.versiontracker.com/dyn/moreinfo/macosx/21086) would have been perfect because it describes launching or executing a script on those events, but it seems to not work with the leopard now. I know applescript can perform repeating tasks on idle, and that might work, but I can't figure out how to force quit something when the machine is no longer idle.

If you're curious purpose of all of this is to set up a render farm in an office that will not effect other peoples CPU cycles.
daftcain is offline   Reply With Quote
Old 09-30-2008, 04:19 PM   #2
trevor
Moderator
 
Join Date: Jun 2003
Location: Boulder, CO USA
Posts: 19,838
Why don't you make your render-farm application a screensaver? That automatically launches when the computer is idle and quits when the computer is no longer idle, which seems to be exactly what you want without any added fuss.

Trevor
trevor is offline   Reply With Quote
Old 09-30-2008, 09:09 PM   #3
cwtnospam
League Commissioner
 
Join Date: Jan 2005
Posts: 8,475
Can you set the priority (man nice) of the app to be low enough that it can run all the time without interfering? I run Folding@home all the time when my 4 year old Dual G5 is on, and I've never noticed a performance hit because Folding@home is set to low priority by default.
cwtnospam is offline   Reply With Quote
Old 10-01-2008, 05:02 AM   #4
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
Here is an old script I had,that you can play with.

It will check the idle state every 20 seconds.
if the idle state is less than 20 seconds ( i.e a key clicked in the last 20 seconds) then it will quit in this case textedit.app.

if the idle time is more than 120 seconds ( no key clicked for a minute and half) it will launch textedit.app

Code:
property idleCheck : 20 as integer
property idleCheck_usr : 120 as integer
set timer to 0
on idle
	--Check idle time
	set idletime to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"
	set idletime to idletime as string
	set idletime to idletime as integer
	
	tell application "System Events"
		
		
		if idletime is less than idleCheck then (* 20 is 20 seconds. If a key was  tapped 
		within the idleCheck  seconds, it  quits the app. *)
			tell application "TextEdit" to quit
			
			return idleCheck -- checks again in ... seconds
		else
			if idletime is greater than idleCheck_usr then (*  If a key was tapped 
		after the idleCheck_usr  seconds it t opens the app. *)
				tell application "TextEdit" to launch
				
			end if
			
			return idleCheck -- 
			
		end if
		
	end tell
end idle
__________________
MH.
mark hunte is offline   Reply With Quote
Old 10-01-2008, 08:28 AM   #5
daftcain
Registered User
 
Join Date: Sep 2008
Posts: 2
Thanks for the replies, I'm sure one of these will work. The simplest sounds like making the app a screen saver, but I don't exactly see a way to choose the application from within the screen saver system preferences. Do I have to change the program in some way so it shows up as a screen saver?

looks like any of the other solutions can work too
daftcain is offline   Reply With Quote
Old 10-01-2008, 02:45 PM   #6
trevor
Moderator
 
Join Date: Jun 2003
Location: Boulder, CO USA
Posts: 19,838
Quote:
Originally Posted by daftcain
Thanks for the replies, I'm sure one of these will work. The simplest sounds like making the app a screen saver, but I don't exactly see a way to choose the application from within the screen saver system preferences. Do I have to change the program in some way so it shows up as a screen saver?

looks like any of the other solutions can work too

There's probably a more elegant way to make an app directly into a screensaver, but one method to make this work is to use ScriptSaver, which is a screensaver that will launch an Applescript. If that Applescript launches your app, that should work to start the app, although I'm not sure about automatically quitting your app when the computer ceases to be idle.

Trevor
trevor is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:59 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.