Jump to content

Run Selected Text


Recommended Posts

When browsing these forums, and want to try out the codes posted by members, what I try to do is right click on the desktop and create a new (blank) AutoIt script, open it in Scite, and copy and paste the posted code, save the au3 file and run it.

Well, this is tedious as you may note. The code that follows is my attempt to make life a bit easier for me. Can't say if it could be useful to others but I thought I'd share it. :D

BTW, I compiled it and created a shortcut with shortcut keys so that I can call it up even when I am browsing the internet and will not need to minimize my browser or click on anything else. In my case I set Ctrl+Alt+Shift+q to call it up.

TO use it, I just highlight a bunch of autoit code and hit the shortcut keys...

NOTE: If the highlighted text is not autoit code, it will just return an error and exit.

EDIT: Added (1) check to see if clipboard is empty and (2) ESC hotkey to make it easy to exit


$Script = 'HotKeySet("{ESC}","_Exit")' & @CRLF & 'Func _Exit()' & @CRLF & 'Exit' & @CRLF & 'EndFUnc' & @CRLF

$TempScript = @ScriptDir & "\tempscript.au3"; the temp script, this will be deleted later

$OldClip = ClipGet() ; the original contents of the clipboard
Send("^c")           ; copy the highlighted text
$Script = $Script & ClipGet()  ;   and store it in a var for writing later

ClipPut($OldClip)    ; done using the clipboard so restore the original contents
;~ If $Script = ";debug" & @CRLF Then Exit

; clear the temp script (if exists) before updating its contents
If FileExists($TempScript) Then FileDelete($TempScript)

; write the code into a file to be able to run it

;~ While Not FileExists($TempScript)
;~;wait for the temporary script to be created
;~ Wend

; I'm using this on two machines and I don't want to hardcode the autoit3.exe path
$AutoIt = StringTrimRight(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\AutoIt3.exe\shell\Open\Command",""),28)   
RunWait($AutoIt & ' "' & $TempScript & '"'); run the script

; give an opportunity to edit the code in Scite before deleting it
TrayTip("Temp Script","Press Ctrl+e to edit the file. Closing in 3 seconds.",3)


Func _Edit(); if I want to edit the code
 $Scite = StringTrimRight(RegRead("HKEY_CLASSES_ROOT\AutoIt3Script\Shell\Edit\Command",""),5)
 Run ($Scite & ' "' & $TempScript & '"')

Func _Exit()
Edited by kalayaan
Link to comment
Share on other sites

When i ran it it started multiplying and I had to shut down my computer and reboot . I had about 20 of them in the system tray before I got shut down and rebooted..

Link to comment
Share on other sites

OMG!!! I see what you mean.

That would happen if you run it without anything selected. You see it copies anything that is highlighted into the clipboard and saves this into an autoit file and then runs it.

I didn't foresee that happening and didn't try running it without anything highlighted. Sorry for that bob. Stupid of me. :D

I'll look at the code more closely, in the meantime, I edited it to put an ESC hotkey in the temp script, and removed the while loops that may be respawning the program.

Thanks for the feedback.

Edited by kalayaan
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...