script to close down a program

EricM

Daemon Poster
Messages
635
I am trying to find a way to close down a program (itunes) after it remains inactive or idle for a period of time. is there a script or something that can do this?

i am running windows 7.
 
To be honest, Im not 100% on how to do this, but could you steal (use and modify :p) some script form a screen saver.

I.E. (in basic terms)

WHEN
Mouse is idle for 1min or greater
DISPLAY <images>

then instead of display images, <close itunes>

Thats one idea.

EDIT: Something along the lines of this may also work - im very tired / delusional at the moment - apologies if it is wrong / unclear (and I know its not fully complete / functional - just an idea)

EndProcess = itunes.exe

Select* Win32_Process (select everything running on windows)


FOR each process

IF
Process.name = EndProcess
THEN
Process.terminate
END IF

NEXT
 
Screensavers don't run as scripts - scr files are merely exe's with a renamed extension. They're invoked by windows when you've been inactive for a while, the "detecting inactivity" part isn't held in the screensavers themselves.

On top of that, what do you mean by inactive? If you mean when you're inactive at your PC, you could use a method similar to the above - just code a program that closes down itunes if it's running, rename it to .scr and install it as a screensaver. Should work in theory, though I've never tried it.

If you mean when itunes is inactive however - that's far trickier, I can't think of a way to do that off the top of my head. If there is I can pretty much guarantee it won't be a nice way!

I guess the deeper question is why do you want to do this? Itunes sits in my system tray when it's not being used without any issues at all.
 
That is tricky. There is an API of some description which let's you get the name of the song which is currently playing... in theory, you could make a script/program which would monitor what was being played, and if it stayed on the same song for more than X minutes, it would close iTunes...?
 
That is tricky. There is an API of some description which let's you get the name of the song which is currently playing... in theory, you could make a script/program which would monitor what was being played, and if it stayed on the same song for more than X minutes, it would close iTunes...?
But what about long songs? I've got some that last 3 minutes, and some concertos that go on for hours. And what about if the same song is looped over and over again? I'm not sure you could reliably address the issue that way - interesting approach though.
 
I'm fairly sure that they tell you how many minutes/seconds you are into the song. If the song position timer-thingie keeps moving, then you could assume that the song is still playing. If it did not increase with time, then you could assume that it was paused :D
 
I'm fairly sure that they tell you how many minutes/seconds you are into the song. If the song position timer-thingie keeps moving, then you could assume that the song is still playing. If it did not increase with time, then you could assume that it was paused
I wasn't aware of any APIs that worked that way - but sure, if they do, that's probably your best bet!
 
Well I'm pretty sure that there must be - Otherwise things like Last.FM and my Logitech G15's LCD wouldn't work, would they?
 
you could just use a shell command to send the system command
taskkill /IM itunes.exe

this will shut down itunes. perhaps add /f to force it.

if you want it to be when idle then you;re going to have to do as above and trap mouse movements or key strokes.

or save the .exe as a .scr file and run it as a screen saver.

there are a few things that can hook into the API to monitor song name and process... I don't know how many of these work with itunes.

LCD smartie is a program that send the current playing list to an external LCD screen, I think they release the source as GPL so you could have a look at how the hook into it here... -I don't imagine that apple will have documented their API to allow you to figure it out easily by yourself, if at all.
 
Back
Top Bottom