Page 1 of 1

Hi, little help please.

Posted: Mon Feb 08, 2010 2:27 am
by so2easy
Im trying to make a script that will auto-restart a certain program for me in some time interval.
Like 5hours.

Code: Select all

function main()

  while(1) do

  printf("Hello to auto-restart script.\n");
  printf("Press SPACE BAR to terminate script.\n");
  mouseSet(1310, 101);
  mouseLClick();
  mouseLClick();
  rest( 20000 );
  mouseSet(910, 46); 
  mouseLClick();
  rest( 2000 );
  mouseSet(1080, 130); 
  mouseLClick();
  rest( 2000 );
  mouseSet(264, 94);  
  mouseLClick();
  rest( 2000 );
  mouseSet(547, 318);  
  mouseLClick();
  rest( 2000 );
  mouseSet(1348, 10); 
  mouseLClick();
  rest( 2000 );
  mouseSet(872, 543);  
  mouseLClick();
  rest( 20000 );
   

    if( keyPressedLocal(key.VK_SPACE) ) then
      break;
    end
  end
 
  printf("Goodbye!\n");
 
end
 
 
-- startMacro will now call main() within a protected environment for us.
startMacro(main);
This is what ive done, what i can do atm.
Any better ideas, or mistakes i made?


Anyway i can make this run in background while im watching a movie or something? Will be awesome.

Re: Hi, little help please.

Posted: Tue Feb 09, 2010 12:12 pm
by so2easy
This is what im using atm.

Code: Select all

 local lastUpdateTime = 0;

while(true) do
  if( os.difftime(os.time(), lastUpdateTime) > 60*60*3 ) then
    lastUpdateTime = os.time();

  logMessage("");

  printf("Hello to auto-restart script.\n");
  printf("Press SPACE BAR to terminate script.\n");
  mouseSet(1310, 101);
  mouseLClick();
  mouseLClick();
  rest( 20000 );
  mouseSet(910, 46); 
  mouseLClick();
  rest( 2000 );
  mouseSet(1080, 130); 
  mouseLClick();
  rest( 2000 );
  mouseSet(264, 94); 
  mouseLClick();
  rest( 2000 );
  mouseSet(547, 318); 
  mouseLClick();
  rest( 2000 );
  mouseSet(1348, 10); 
  mouseLClick();
  rest( 2000 );
  mouseSet(872, 543);  
  mouseLClick();

     if( keyPressedLocal(key.VK_SPACE) ) then
      printf("Goodbye!\n");
        break;

    end
    
  end

  yrest(100); 

end
Trying to make it better with time.. currently am staring at the lua webpage trying to make it somehow attach to the program and when the process closes to start it.. not on timer.

Re: Hi, little help please.

Posted: Tue Feb 09, 2010 7:55 pm
by Administrator
so2easy wrote: Trying to make it better with time.. currently am staring at the lua webpage trying to make it somehow attach to the program and when the process closes to start it.. not on timer.
system().

Code: Select all

if( string.find(system('tasklist /fi "imagename eq whatever.exe" /NH'), "No tasks are running", true) ) then
  -- The program is not running. Do something.
end

Re: Hi, little help please.

Posted: Wed Feb 10, 2010 11:39 am
by so2easy

Code: Select all

scripts\tashakdve.lua:1: attempt to call global 'system' (a nil value)
This is probably some really stupid error but cant seem to fix it. :D

Code: Select all

if( string.find(system('tasklist /fi "Blablabla.exe" /NH'), "No tasks are running", true) ) then

  logMessage("");

while(true) do

  printf("Hello to auto-restart script.\n");
  printf("Press SPACE BAR to terminate script.\n");
  mouseSet(1310, 101);
  mouseLClick();
  mouseLClick();
  rest( 20000 );
  mouseSet(910, 46); 
  mouseLClick();
  rest( 2000 );
  mouseSet(1080, 130); 
  mouseLClick();
  rest( 2000 );
  mouseSet(264, 94);  
  mouseLClick();
  rest( 2000 );
  mouseSet(547, 318);  
  mouseLClick();
  rest( 2000 );
  mouseSet(1348, 10); 
  mouseLClick();
  rest( 2000 );
  mouseSet(872, 543);  
  mouseLClick();

     if( keyPressedLocal(key.VK_SPACE) ) then
       break;

    end
     printf("Goodbye!\n");
  end

  yrest(100); -- minimize CPU usage when not busy

end

Re: Hi, little help please.

Posted: Wed Feb 10, 2010 12:06 pm
by Administrator
You're using an outdated version of MicroMacro. Also, I made an error in the example I gave. You should just get rid of the 'true' from the string.find() call.

Re: Hi, little help please.

Posted: Wed Feb 10, 2010 7:59 pm
by so2easy
After update:

Code: Select all

ERROR: The search filter cannot be recognized.

Re: Hi, little help please.

Posted: Wed Feb 10, 2010 8:53 pm
by Administrator
You put:

Code: Select all

tasklist /fi "Blablabla.exe" /NH
There is a reason I formatted it the way I did in my example. You must have:

Code: Select all

tasklist /fi "imagename eq Blablabla.exe" /NH

Re: Hi, little help please.

Posted: Thu Feb 11, 2010 3:26 pm
by so2easy
Oh, i probably deleted it by mistake. Anyway fixed now.. but i think my syntax is wrong or i am missing to add something.

On stopped program - no process:
INFO: No tasks running with the specified criteria.
On runnign program - finds process and doesnt do anything.

Code: Select all

if( string.find(system('tasklist /fi "imagename eq Blablabla.exe" /NH'), "No tasks are running") ) then

  printf("Hello to auto-restart script.\n");
  printf("Press SPACE BAR to terminate script.\n");
  mouseSet(1310, 101);
  mouseLClick();
  mouseLClick();
  rest( 20000 );
  mouseSet(910, 46); 
  mouseLClick();
  rest( 2000 );
  mouseSet(1080, 130); 
  mouseLClick();
  rest( 2000 );
  mouseSet(264, 94);  
  mouseLClick();
  rest( 2000 );
  mouseSet(547, 318);  
  mouseLClick();
  rest( 2000 );
  mouseSet(1348, 10); 
  mouseLClick();
  rest( 2000 );
  mouseSet(872, 543);  
  mouseLClick();

    end

  yrest(100); -- minimize CPU usage when not busy

Re: Hi, little help please.

Posted: Thu Feb 11, 2010 5:15 pm
by Administrator
And why did you put that where you did? It's a simple check of whether or not the program is running, which is what you asked for. You put the code that you want to run when the program is/is not running inside there, not the whole script.