idle time


#1 how to get the idle time of user applications ? (name and eventually the idle time)
#2 works /usr/bin/uptime for both startup login AND user login ?
#3 exists something similar to uptime, but for the time one connects with the internet ?


I think you may find logging domains in asl that does what you want, but doesn’t know for sure.

As for network uptime, I’d create applets that opens the interface, and adds a log entry, you’ll close the interface with the same applet, and then write another log entry, you can add some logic for pruning it if it is a new day. In the end you can then summarize the log entries, with something, and know how long you have been connected, that day.

that are great news! .i started instantly to search for asl and similar. It IS a good direction.

i use a menulet to track my network uptime, the plugin is found here:

the executable file has no man entry.
error “sh: /System/Library/CoreServices/Menu Extras/ cannot execute binary file” number 126

would be interesting to know from where this tiny plugin grabs its info, i like precise values. The problem is, that i need the network uptime whilst i navigate to keep my taxes low.
Self-made timers in idle-applescript apps -as i developed- have proven to be reliable most of the time (98%), but rare times, this clock has failed for 1-2 minutes. Which takes me to consider improvements.


When an executable is within a menulet, then it may need some resources, or have its resources loaded and connected with the SystemUI Server when it is starting, so it is not given that it will run from the commandline. That is, it probably need to be run from within a configured context. Sorry about that.

I think the uptime command from the shell will give you the uptime, since you logged in last. Maybe if you are in luck, you will spot a difference if you sudo uptime.

i read a long time now about asl and syslog in man pages and on the web. I couldn’t find a solution for my problem, which is the following:
i get always lots of apps running and loose a bit the oversight, when i need to switch from one app to another, between others which aren’t more in use. So i want to quit idle apps after a certain timeout. I don’t need a complete step by step tutorial, i need “only” to get the names and eventually, the times of idle apps.
I’m on Lion and happy with my Os, upgrading to a higher Os (who integrates such a feature) would not work for me, breaking some applications i use regularly.

i drafted a first code of my idea. However, its a rough way to
determine if apps are running idle and should be closed. I removed the idle-handler for the script, because i run it through launchd

Some thoughts to improve this line ?

		set running_apps to name of processes whose background only is false and visible is false

Here the script:

property idle_apps : {}
property bl_ls : {"Black Light", "Finder"}

on run
	tell application "System Events"
		set running_apps to name of processes whose background only is false and visible is false
		repeat with a in running_apps
			if a is in idle_apps then #30mins
					quit process a
				end try
				set clean_oldapps to {}
				repeat with b in idle_apps
					if b is in running_apps then copy b to end of clean_oldapps
				end repeat
				set idle_apps to clean_oldapps
				copy a to end of idle_apps
			end if
		end repeat
	end tell
end run

I went further.
After some research i figured out to need process state. However, and ironically, the result my shell produces now isn’t clear to me. An application running more than 20 secs in the background should be considered as “idle”.
The time interval to check if an app is idle or not is set best at 5 minutes, i think.

tell application "System Events" to set unid to unix id of process "iCal"
set f to (do shell script "ps " & unid & " -o state=I  || echo 'false'")
log f


You would also want to test for a timeout, in a try error blockwhen you try to kill an app, because it may be unresponsive, due to unsaved docs and so on.

I still recommend creating a bootable usb stick with Mavericks 10.9.1 (lots of issues fixed), and see if that will do the trick for you. This will not autoquit older apps though, so your idle app is still very useful. :slight_smile:

Merry Christmas, and a Happy New Year to All!

If Caesar got a coin every time he save a depiction of him, he’d have it going.

yes, you’re right. However, these are peanuts/details, actually. Most of my bigger scripts today have some breath and this gave me a bit of experience.
The greater issue i have now is the shell code using ps. I would accept gladly some suggestions how to change it to something working.
I’ll try Maverick, without doubt, but with calm.

Merry Christmas to you too !


Every thing is per definition idle when your ps command runs. And nothings shows up as idle. You can’t even write -o state=I for filtering out the idle processes anyway. It doesn’t exit with an error code, but it doesn’t seem to give any results from the commandline in a Terminal window either.

Sleeping and idle isn’t the same, I think ps’s definition of idle, is that a process is sleeping by having set an alarm as to when it shall awake again, in seconds, whereas you want to know about applications that has been inactive, which is an entirely different thing.

I think the closest you can get to your goal, is to see which apps that isn’t foreground, and increment a counter by 1 every 20 second or so, when the counter has reached 15, it is idle, and should be closed.

I’d go for something like 10 or 15 minutes personally.

I hope this helps.

this is the initial idea i played with, and to be honest, seems to me too, the only traceable way to go. I tried with ps because top seems so complicated to use. Isn’t -there- a command i could use to reveal idle times ? :confused:

There probably is a way to find out which apps has been idle, but I know of none. You can’t use System Events, you need some commandline tool, or something made up with Apple’s private Frameworks. The ideal thing would be to listen for activity on the macports between the window server and the apps, but I don’t know how to do this.

I think you should find something if you google intensively.