OK..How can i make this clear? I love to listen to a song until i fall asleep in the night.But i don't like to turn on my laptop even after the playlist have finished. Let say my Playlist is only 1 hour, after i fall asleep, my laptop is still on and wasting my electricity bill. If i use shutdown timer, the shutdown timer shuts down my computer without closing my iTunes first.Is there any way i can create a script to safely close iTunes first before shutting down my laptop?
AutoIt is your answer, dude. Code: While @HOUR < 12 Sleep(500); Check the clock two times per second WEnd ; When the time is right, ProcessClose("itunes.exe"); This will close the process as if you clicked the X in the upper right corner of the iTunes window. Exit I really have to get going now, but I would have added some error checking in there, etc. If you want to make use of this approach then I'll be happy to assist you writing a proper script. Later dude
thanks for the reply calistoga.Will check it rite now update : so how do i find or run the script? Is it the script that u've posted above?save as .au3 files in notepad?
Yeah, Notepad is fine, but I would recommend using the SciTE editor that I've mentioned here (follow the steps in 1.2 if you haven't done already). It's got syntax highlighting, code completion etc This is one of the functions you might find useful: Code: Shutdown(1); Where the numerical value means: Code: 0 = Logoff 1 = Shutdown 2 = Reboot 4 = Force 8 = Power down 32= Standby 64= Hibernate If you want to know about a specific function, I can recommend the AutoIt Help File (F1 in SciTe) as it is very complete and well written. Please do ask if you got any questions
Code: While @HOUR < 12 Sleep(500); Check the clock two times per second WEnd ; When the time is right, ProcessClose("itunes.exe"); This will close the process as if you clicked the X in the upper right corner of the iTunes window. Exit "when the time is right"..i might have confused a bit there
This loop will run as long as @HOUR is less than 12 (ex 12 PM). The Sleep() thingy in there is because we don't want to make the CPU run at 100% while processing the loop. This code is evaluating two times per second (because of Sleep(500), where 500 milliseconds = 1/2 sec. Code: While @HOUR < 12 Sleep(500); Check the clock two times per second WEnd With this I mean, "when the clock has reached 12 or any other desired point in time" (when the above loop has finished beacause the clock reached 12). You could say we're pausing the program, until you want it to end itunes and shut down the computer. Code: ; When the time is right, ProcessClose("itunes.exe"); This will close the process as if you clicked the X in the upper right corner of the iTunes window. This one isn't really necessary, as the script will end anyways, but I usually keep it in there for readability Code: Exit
While @HOUR < 12 Sleep(500); Check the clock two times per second WEnd 12 in the morning or evening? if the time should be specified clearly?
Dude, the Windows Task Sheduler is all you need...you can execute any command including taskkill.exe and shutdown.exe I have a timer if I fall asleep my laptop will shut off at a certain time Code: schtasks /create /sc DAILY /tn "Power Off" /tr "shutdown /s /t 60 /c \"Your PC will shutdown in approximately 1 minute.\"" /st 05:00 /f You can also add other stuff to execute like taskkill.exe to kill any processes (I recommend process.exe its very good a closing apps, less forceful) Code: process.exe -q <task_name>.exe