Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-07-2010, 08:46 PM   #1
Daemon Poster
 
Join Date: Sep 2005
Posts: 635
Default script to close down a program

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.
__________________

EricM is offline   Reply With Quote
Old 03-09-2010, 06:43 AM   #2
In Runtime
 
Join Date: Jan 2010
Posts: 320
Default Re: script to close down a program

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
__________________

Luke_Uk_Baggy is offline   Reply With Quote
Old 03-09-2010, 02:05 PM   #3
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: script to close down a program

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.
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 03-14-2010, 07:27 AM   #4
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: script to close down a program

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...?
j03 is offline   Reply With Quote
Old 03-14-2010, 01:09 PM   #5
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: script to close down a program

Quote:
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.
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 03-17-2010, 06:13 PM   #6
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: script to close down a program

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
j03 is offline   Reply With Quote
Old 03-17-2010, 07:16 PM   #7
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: script to close down a program

Quote:
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!
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 04-15-2010, 03:23 PM   #8
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: script to close down a program

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?
j03 is offline   Reply With Quote
Old 04-16-2010, 10:54 AM   #9
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: script to close down a program

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.
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 04-17-2010, 09:35 AM   #10
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: script to close down a program

http://developer.apple.com/sdk/itunescomsdk.html
__________________

j03 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 02:17 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0