c00p 0 Posted July 28, 2011 Hello, yesterday I've written my very first own script to test some commands, I compiled it but when i sent it to my friend, he said that the MsgBox from the beginning opens 2 times at his computer. Well, so heres the code: $IP = ("Paste") $M1 = MsgBox(1,"Pastesaver by c00p","Drücke OK um deinen zwischengespeicherten Text zu speichern. ") If $M1 = 1 then Run("notepad.exe") Send("^v") Send("^s") Sleep(500) Send($IP &".txt") send("{ENTER}") Send("!{F4}") Else Exit EndIf Well, when I start it the MsgBox just opens once, that how it should be. Can anyone here help me? postal script: sorry for my bad english, i'm from germany and just got B+ in english.. Share this post Link to post Share on other sites
DarkestHour 0 Posted July 28, 2011 Try this: $IP = ("Paste") If MsgBox(1,"Pastesaver by c00p","Drücke OK um deinen zwischengespeicherten Text zu speichern. ") = 1 then Run("notepad.exe") Send("^v") Send("^s") Sleep(500) Send($IP &".txt") send("{ENTER}") Send("!{F4}") Else Exit EndIf Also, you may want to think about adding in a WinWaitActive to wait for notepad to actually be open before it does it's routine. Share this post Link to post Share on other sites
sleepydvdr 8 Posted July 28, 2011 How about something like this: #include <file.au3> $IP = ("Paste") $M1 = MsgBox(1,"Pastesaver by c00p","Drücke OK um deinen zwischengespeicherten Text zu speichern. ") If $M1 = 1 then _FileCreate($IP & ".txt") $data = ClipGet ( ) FileWrite($IP & ".txt", $data) Else Exit EndIf #include <ByteMe.au3> Share this post Link to post Share on other sites
DarkestHour 0 Posted July 28, 2011 @sleepydvdr: Right on, but i was actually having the problem he mentioned as well, the $M1 in the if statement was actually running the msgbox a second time somehow when it is compiled, so i just took out the $M1 altogether since it really isnt needed for what he was doing, so with your much improved example: #include <file.au3> $IP = ("Paste") If MsgBox(1,"Pastesaver by c00p","Drücke OK um deinen zwischengespeicherten Text zu speichern. ") = 1 then _FileCreate($IP & ".txt") $data = ClipGet ( ) FileWrite($IP & ".txt", $data) Else Exit EndIf Share this post Link to post Share on other sites
sleepydvdr 8 Posted July 28, 2011 And just to let you know what was going wrong with your original script... You run notepad. But you have no delay and start sending controls before notepad has opened. You paste, which does nothing. You save, but it does nothing. You send the word "Paste" and press enter. Notepad still hasn't opened yet, so what happens is you are selecting an executable that starts with the letter "P" and press enter. You have just ran your executable a second time. By now, Notepad is open and the second executable pastes the text in the first Notepad. If you ask your friend, I bet he will tell you a second instance of Notepad opened up, but nothing was written to it. The code I posted above avoids this problem. #include <ByteMe.au3> Share this post Link to post Share on other sites
c00p 0 Posted July 28, 2011 Thank you for the explanation and the solvage code, but I modified my code a bit and it worked perfect. If it's how it goes in this forum, you can close this thread. Share this post Link to post Share on other sites