Bozzman Posted October 26, 2008 Posted October 26, 2008 cool:P can you post your version 2? so i can check whats improved
RWBaker Posted October 26, 2008 Posted October 26, 2008 cool:P can you post your version 2?so i can check whats improvedOK, here is my latest version...do let me know if you have any suggestions, etc.CODEMsgBox(64, "First time use note:", "You must check out the Consts below! Especially the first, $move_to_dir!")Exit#include <Misc.au3>;Script: au3 on Clip.au3 - Allows the user to execute and/or edit au3 code from the Clipboard.;Original Author: Bozzman - copied from the AutoIt user forum on 10/24/2008.;Revised by RW_Baker on 10/26/2008._Singleton("au3 on Clip", 0)AutoItWinSetTitle(@ScriptName);These consts must be checked for your use:Const $move_to_dir = "F:\AutoIt" ;<- The move operation moves the temp file to this directory.Const $temp_file_name = "\DebugScript.au3" ;<- The temp file name preceeded by a "\"Const $temp_file_path = @TempDir & $temp_file_name ;<- The full temp file pathHotKeySet("^r", "runscript")HotKeySet("^s", "openscript")HotKeySet("^m", "movescript")HotKeySet("^q", "quit")HotKeySet("^?", "help")#cs The original settings: HotKeySet("^q","runscript") HotKeySet("^w","openscript") HotKeySet("^s","quit")#ceIf FileExists($temp_file_path) Then FileDelete($temp_file_path) ; get rid of old temp fileOpt("TrayAutoPause", 0)Opt("TrayMenuMode", 1)TraySetClick(16)TrayCreateItem("Made By Bozzman")TrayCreateItem("")TrayCreateItem("")$scripthelpitem = TrayCreateItem("Help CTRL+?")$scriptitem = TrayCreateItem("Run Clipbord Script CTRL+R")$scriptopenitem = TrayCreateItem("Open Clipbord Script CTRL+S")$scriptmoveitem = TrayCreateItem("Move Saved File CTRL+M")TrayCreateItem("")$quititem = TrayCreateItem("Quit Program CTRL+ Q")help()Call("idle")Func idle() While True $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $scriptitem Call("runscript") Case $msg = $scriptopenitem Call("openscript") Case $msg = $scripthelpitem Call("help") Case $msg = $scriptmoveitem Call("movescript") Case $msg = $quititem Call("quit") EndSelect WEndEndFunc ;==>idleFunc runscript() $Code = ClipGet() $File = FileOpen($temp_file_path, 2) FileWrite($File, $Code) FileClose($File) Run(@ProgramFilesDir & "\Autoit3\autoit3.exe " & @TempDir & $temp_file_name) Call("idle")EndFunc ;==>runscriptFunc openscript() $Code = ClipGet() $the_file = $temp_file_path $File = FileOpen($temp_file_path, 2) FileWrite($File, $Code) FileClose($File) Run(@ProgramFilesDir & "\Autoit3\SciTE\SciTE.exe " & @TempDir & $temp_file_name) Call("idle")EndFunc ;==>openscriptFunc movescript() If FileExists($temp_file_path) Then $did_move = FileMove($temp_file_path, $move_to_dir) If $did_move Then MsgBox(64, @ScriptName, "The move was successful.", 3) Else MsgBox(64, @ScriptName, "The move cannot be done because the file already exists in: " & $move_to_dir, 3) EndIf Else MsgBox(64, @ScriptName, "There is no file to move.", 3) EndIf ReturnEndFunc ;==>movescriptFunc quit() MsgBox(64, @ScriptName, "Program termination.", 2) ExitEndFunc ;==>quitFunc help() $help = "CTRL+r -> Run the script" & @CRLF $help &= "CTRL+s -> Open the script" & @CRLF $help &= "CTRL+m -> Move the script to: " & $move_to_dir & @CRLF $help &= "CTRL+q -> Quit the program" & @CRLF $help &= 'CTRL+? -> Help(Note: you must hold "Shift" down, too.)' MsgBox(0, "Help:", $help) ReturnEndFunc ;==>help#cs ; Copy to the Clipboard for testing: #include <Date.au3> MsgBox(64,@ScriptName,"testing...should be Monday, it is: "&_DateDayOfWeek(2))#ce RW Baker
Bozzman Posted October 26, 2008 Posted October 26, 2008 (edited) OK, here is my latest version...do let me know if you have any suggestions, etc. I made a direct save option of custom location and added you in creditxD (Func savescript()) [edit] next post comments CODEMsgBox(64, "First time use note:", "You must check out the Consts below! Especially the first, $move_to_dir!") Exit #include <Misc.au3> ;Script: au3 on Clip.au3 - Allows the user to execute and/or edit au3 code from the Clipboard. ;Original Author: Bozzman - copied from the AutoIt user forum on 10/24/2008. ;Revised by RW_Baker on 10/26/2008. _Singleton("au3 on Clip", 0) AutoItWinSetTitle(@ScriptName) ;These consts must be checked for your use: Const $move_to_dir = "F:\AutoIt" ;<- The move operation moves the temp file to this directory. Const $temp_file_name = "\DebugScript.au3" ;<- The temp file name preceeded by a "\" Const $temp_file_path = @TempDir & $temp_file_name ;<- The full temp file path HotKeySet("^r", "runscript") HotKeySet("^s", "openscript") HotKeySet("^m", "movescript") HotKeySet("^q", "quit") HotKeySet("^?", "help") HotKeySet("^i", "savescript") #cs The original settings: HotKeySet("^q","runscript") HotKeySet("^w","openscript") HotKeySet("^s","quit") #ce If FileExists($temp_file_path) Then FileDelete($temp_file_path) ; get rid of old temp file Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) TraySetClick(16) TrayCreateItem("Made By Bozzman & RW_Baker") TrayCreateItem("") TrayCreateItem("") $scripthelpitem = TrayCreateItem("Help CTRL+?") $scriptitem = TrayCreateItem("Run Clipbord Script CTRL+R") $scriptopenitem = TrayCreateItem("Open Clipbord Script CTRL+S") $scriptmoveitem = TrayCreateItem("Move Saved File CTRL+M") $scriptsaveitem = TrayCreateItem("Save Script File CTRL+I") TrayCreateItem("") $quititem = TrayCreateItem("Quit Program CTRL+ Q") help() Func idle() While True $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $scriptitem Call("runscript") Case $msg = $scriptopenitem Call("openscript") Case $msg = $scripthelpitem Call("help") Case $msg = $scriptmoveitem Call("movescript") Case $msg = $scriptsaveitem Call("savescript") Case $msg = $quititem Call("quit") EndSelect WEnd EndFunc ;==>idle Func runscript() $Code = ClipGet() $File = FileOpen($temp_file_path, 2) FileWrite($File, $Code) FileClose($File) Run(@ProgramFilesDir & "\Autoit3\autoit3.exe " & @TempDir & $temp_file_name) Call("idle") EndFunc ;==>runscript Func openscript() $Code = ClipGet() $the_file = $temp_file_path $File = FileOpen($temp_file_path, 2) FileWrite($File, $Code) FileClose($File) Run(@ProgramFilesDir & "\Autoit3\SciTE\SciTE.exe " & @TempDir & $temp_file_name) Call("idle") EndFunc ;==>openscript Func movescript() If FileExists($temp_file_path) Then $did_move = FileMove($temp_file_path, $move_to_dir) If $did_move Then MsgBox(64, @ScriptName, "The move was successful.", 3) Else MsgBox(64, @ScriptName, "The move cannot be done because the file already exists in: " & $move_to_dir, 3) EndIf Else MsgBox(64, @ScriptName, "There is no file to move.", 3) EndIf call("idle") Return EndFunc ;==>movescript Func savescript() $filesave = FileSaveDialog("Save File", $move_to_dir, "Scripts (*.au3)", 2) $Code = ClipGet() If StringInStr($filesave,".au3")>0 Then $File = FileOpen($filesave, 2) FileWrite($File, $Code) FileClose($File) Else MsgBox(0,"Save File","No .au3 found in string please resave") EndIf Call("idle") EndFunc ;==>savescript Func quit() MsgBox(64, @ScriptName, "Program termination.", 2) Exit EndFunc ;==>quit Func help() $help = "CTRL+r -> Run the script" & @CRLF $help &= "CTRL+s -> Open the script" & @CRLF $help &= "CTRL+m -> Move the script to: " & $move_to_dir & @CRLF $help &= "CTRL+i -> Save the script on a custom location"& @CRLF $help &= "CTRL+q -> Quit the program" & @CRLF $help &= 'CTRL+? -> Help(Note: you must hold "Shift" down, too.)' MsgBox(0, "Help:", $help) Call("idle") Return EndFunc ;==>help #cs ; Copy to the Clipboard for testing: #include <Date.au3> MsgBox(64,@ScriptName,"testing...should be Monday, it is: "&_DateDayOfWeek(2)) #ce Edited October 27, 2008 by Bozzman
RWBaker Posted October 27, 2008 Posted October 27, 2008 "savescript" is a very good addition. Here are some notes on the last version that you submitted: In Func movescript(): There is no Call("idle") before the return (I originally forgot to put it in) In Func savescript(): The Call("idle") is in the else of the last if statement...it shoud be moved to before the Return. Also: The first statement in this func has "$move_to_dir" as the second argument to FileSaveDialog...the quotes should be removed giving: $filesave = FileSaveDialog("Save File", $move_to_dir, "Scripts (*.au3)", 2) In Func help(): There is no Call("idle") before the Return (I originally forgot to put it in) RW_Baker RW Baker
Bozzman Posted October 27, 2008 Posted October 27, 2008 little improvement in savescript() auto name .au3 and cancel added maybe you can make someting that reads the title and put that in default expandcollapse popupMsgBox(64, "First time use note:", "You must check out the Consts below! Especially the first, $move_to_dir!") Exit #include ;Script: au3 on Clip.au3 - Allows the user to execute and/or edit au3 code from the Clipboard. ;Original Author: Bozzman - copied from the AutoIt user forum on 10/24/2008. ;Revised by RW_Baker on 10/26/2008. _Singleton("au3 on Clip", 0) AutoItWinSetTitle(@ScriptName) ;These consts must be checked for your use: Const $move_to_dir = "F:\autoit";<- The move operation moves the temp file to this directory. Const $temp_file_name = "\DebugScript.au3" ;<- The temp file name preceeded by a "\" Const $temp_file_path = @TempDir & $temp_file_name ;<- The full temp file path HotKeySet("^r", "runscript") HotKeySet("^s", "openscript") HotKeySet("^m", "movescript") HotKeySet("^q", "quit") HotKeySet("^?", "help") HotKeySet("^i", "savescript") #cs The original settings: HotKeySet("^q","runscript") HotKeySet("^w","openscript") HotKeySet("^s","quit") #ce If FileExists($temp_file_path) Then FileDelete($temp_file_path) ; get rid of old temp file Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) TraySetClick(16) TrayCreateItem("Made By Bozzman & RW_Baker") TrayCreateItem("") TrayCreateItem("") $scripthelpitem = TrayCreateItem("Help CTRL+?") $scriptitem = TrayCreateItem("Run Clipbord Script CTRL+R") $scriptopenitem = TrayCreateItem("Open Clipbord Script CTRL+S") $scriptmoveitem = TrayCreateItem("Move Saved File CTRL+M") $scriptsaveitem = TrayCreateItem("Save Script File CTRL+I") TrayCreateItem("") $quititem = TrayCreateItem("Quit Program CTRL+ Q") help() Func idle() While True $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $scriptitem Call("runscript") Case $msg = $scriptopenitem Call("openscript") Case $msg = $scripthelpitem Call("help") Case $msg = $scriptmoveitem Call("movescript") Case $msg = $scriptsaveitem Call("savescript") Case $msg = $quititem Call("quit") EndSelect WEnd EndFunc ;==>idle Func runscript() $Code = ClipGet() $File = FileOpen($temp_file_path, 2) FileWrite($File, $Code) FileClose($File) Run(@ProgramFilesDir & "\Autoit3\autoit3.exe " & @TempDir & $temp_file_name) Call("idle") EndFunc ;==>runscript Func openscript() $Code = ClipGet() $the_file = $temp_file_path $File = FileOpen($temp_file_path, 2) FileWrite($File, $Code) FileClose($File) Run(@ProgramFilesDir & "\Autoit3\SciTE\SciTE.exe " & @TempDir & $temp_file_name) Call("idle") EndFunc ;==>openscript Func movescript() If FileExists($temp_file_path) Then $did_move = FileMove($temp_file_path, $move_to_dir) If $did_move Then MsgBox(64, @ScriptName, "The move was successful.", 3) Else MsgBox(64, @ScriptName, "The move cannot be done because the file already exists in: " & $move_to_dir, 3) EndIf Else MsgBox(64, @ScriptName, "There is no file to move.", 3) EndIf call("idle") Return EndFunc ;==>movescript Func savescript() $filesave = FileSaveDialog("Save File", $move_to_dir, "Scripts (*.au3)", 2) $Code = ClipGet() If $filesave = "" Then ToolTip("Not saved") Sleep(2500) ToolTip("") Call("idle") EndIf If StringInStr($filesave,".au3")<1 Then $filesave = $filesave&".au3" EndIf $File = FileOpen($filesave, 2) FileWrite($File, $Code) FileClose($File) Call("idle") EndFunc ;==>savescript Func quit() MsgBox(64, @ScriptName, "Program termination.", 2) Exit EndFunc ;==>quit Func help() $help = "CTRL+r -> Run the script" & @CRLF $help &= "CTRL+s -> Open the script" & @CRLF $help &= "CTRL+m -> Move the script to: " & $move_to_dir & @CRLF $help &= "CTRL+i -> Save the script on a custom location"& @CRLF $help &= "CTRL+q -> Quit the program" & @CRLF $help &= 'CTRL+? -> Help(Note: you must hold "Shift" down, too.)' MsgBox(0, "Help:", $help) Call("idle") Return EndFunc ;==>help #cs ; Copy to the Clipboard for testing: #include MsgBox(64,@ScriptName,"testing...should be Monday, it is: "&_DateDayOfWeek(2)) #ce
RWBaker Posted October 28, 2008 Posted October 28, 2008 On savescript(): The cancel logic is fine. I am inclined to just fill in a dummy default file name, something like the following and let the user change it: $filesave = FileSaveDialog($title, $move_to_dir, "Scripts (*.au3)", 2 + 16, "afile.au3") I have been thinking about the need for the Func idle(). I had a hunch that it was not needed, so: * I removed all "Call idle()" statements in the whole script * I removed the "Func idle()" statement and its matching "EndFunc ;==>idle", so that control "runs into" the idle while loop, as follows: ........no change above here in the script TrayCreateItem("") $quititem = TrayCreateItem("Quit Program CTRL+ Q") While True $msg = TrayGetMsg() Select ........ the same body of the Select here EndSelect WEnd ........rest of the script with no call idle's Without the Func idle and the "Call"s, the script runs exactly as before!!!! Simplifies maintenance, too...it's so easy to forget adding those "Call idle()" statements! RW_Baker RW Baker
ronriel Posted October 29, 2008 Posted October 29, 2008 Hi, I actually have been using a simple script like this basically to help me with the examples on the Autoit Helpfile. All you have to do is highlight the part of the script you'd like to run and hit the hotkey. Here it is: ;ronriel's helper HotKeySet ("^r", "Runscript") HotKeySet ("^e", "edit") HotKeySet ("^t", "Terminate") Local $temp = @TempDir&"\AutoitCode.Au3", $PID Func Runscript();run the script get() $PID = Run(@AutoItExe&" "&$temp) EndFunc Func edit();edit the script with your editor, that is, if you have an editor set as the default program to open .au3 scripts. get() ShellExecute($temp) EndFunc Func Terminate();terminate the script. ProcessClose($PID) EndFunc Func get();retreive the script from the clipboard Send("^c") FileClose(FileWrite(FileOpen($temp,2),ClipGet())) EndFunc While 1 Sleep (100000) WEnd Simple but helpful. [font="Comic Sans MS"]-ronriel[/font][topic="48542"]r4r media player[/topic][topic="80836"]OCR & Paste[/topic]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now