 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Fri Nov 10, 2006 7:52 am Post subject: run scripts directly from the forum! |
|
|
While browsing around the forum, I decided i needed the following script, so I wrote it quickly. you may want to change the keys or add it to your base script or whatever. I have new features in mind, but I wanted to post what I have.
| Code: |
#SingleInstance
;takes any highlighted text and creates a temporary script from it
;This lets you select cool functions from the AHK forum and run them right away
;It also should let you run text from any program.
;
;By Branden Gunn - engunneer _AT_ gmail _DOT_ com
;Keys:
;F12: run highlighted text as an ahk script
;Shift F12: Save the highlighted text and open
; it in your default editor - when the editor
; is closed, the script will start
;Alt F12: Open a dialog box to save the last temporary script to somewhere else
; this will automatically add an ahk extension if you forget to do it yourself
F12:: ;run highlighted text
clipboardsaver = ClipboardAll
Send, ^c
ifExist temp.ahk
Filedelete temp.ahk
FileAppend, %Clipboard%`n, temp.ahk
Clipboard = clipboardsaver
clipboardsaver =
run, temp.ahk
Return
+F12:: ;edit then run
clipboardsaver = ClipboardAll
Send, ^c
ifExist temp.ahk
Filedelete temp.ahk
FileAppend, %Clipboard%`n, temp.ahk
Clipboard = clipboardsaver
clipboardsaver =
runwait, edit temp.ahk
run, temp.ahk
Return
!F12:: ;save last script
IfExist temp.ahk
{
;ask user where to copy temp.ahk to
FileSelectFile, destination, S16, , Where do you want to place this awesome script?, Autohotkey Scripts (*.ahk)
If ERRORLEVEL
Msgbox, Script not saved
Else
{
IfNotInString, destination, .ahk
destination = %destination%.ahk
FileCopy, temp.ahk, %destination%, 1
}
}
Return
|
Features:
- does not kill your clipboard
Planned features if anyone wants to give input (or help!):
- Way to change hotkey (don't know how to do this yet, but I've seen other scripts do it)
- A way to append it to another script (for collecting scripts into one file)
- A way to kill the temp script
comments welcome! |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Nov 10, 2006 8:27 am Post subject: |
|
|
Just remember to look at code before you run it..  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Nov 10, 2006 9:21 am Post subject: |
|
|
Mmm, I am disappointed, I expected a browser plug-in...  _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 214 Location: Greeley, CO
|
Posted: Fri Nov 10, 2006 4:16 pm Post subject: Re: run scripts directly from the forum! |
|
|
| engunneer wrote: | | While browsing around the forum, I decided i needed the following script... |
Funny... I had decided the same thing and started to write a similar script last weekend.
I'll just use yours for a while and see how it progresses.
Something from mine that you might want to incorporate in to yours... When Saving, it captures the URL of the script and adds it as a comment at the beginning of the script for future reference. _________________
SoggyDog
Download AutoHotKey Wallpaper
Does 'Fuzzy Logic' tickle? |
|
| Back to top |
|
 |
robiandi
Joined: 08 Aug 2006 Posts: 50
|
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 214 Location: Greeley, CO
|
Posted: Sat Nov 11, 2006 6:51 am Post subject: |
|
|
I liked the flow of your script better than what I had done, so I added a few lines to accomodate my need to capture the URL (and a couple other tiny mods to suit my needs) and this is what I got.
| Code: | #SingleInstance
#NoTrayIcon
SetWorkingDir, %A_Temp%
ClipSaved =
ScriptText =
F12:: ; F12 only: Run highlighted text
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
ScriptText = `; %URL%`r`n`; `r`n%Clipboard%
FileAppend, %ScriptText%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
ScriptText =
run, AHKscript.ahk
Return
+F12:: ; Shift+F12: Edit then run
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
ScriptText = `; %URL%`r`n`; `r`n%Clipboard%
FileAppend, %ScriptText%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
ScriptText =
runwait, edit AHKscript.ahk
run, AHKscript.ahk
Return
!F12:: ; Alt+F12: Save last script
IfExist AHKscript.ahk
{
FileSelectFile, destination, S16, %A_Desktop%, Save Script:, Autohotkey Scripts (*.ahk)
If ERRORLEVEL
Msgbox, Script not saved.
Else
{
IfNotInString, destination, .ahk
destination = %destination%.ahk
FileCopy, AHKscript.ahk, %destination%, 1
}
}
Return |
_________________
SoggyDog
Download AutoHotKey Wallpaper
Does 'Fuzzy Logic' tickle? |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Sat Nov 11, 2006 10:06 pm Post subject: |
|
|
And you fixed some of my bugs  _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 214 Location: Greeley, CO
|
Posted: Sun Nov 12, 2006 8:50 am Post subject: |
|
|
@engunneer:
I didn't mean to take over your thread, but I wanted to share an addition to the script...
Two Emergency Exits (of sorts) were added...
- One allows you to restart (Reload) this script if something goes wrong.
- It's probably not needed, though.
- The other is added to the script being captured in case you can't get out of it any other way.
- This one can come in handy.
| Code: | #SingleInstance
#NoTrayIcon
SetWorkingDir, %A_Temp%
ClipSaved =
Emergency_Exit = ^#!q::ExitApp `; DELETE - This line added by Script Capture System
F12:: ; F12 only: Run highlighted text
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
FileAppend, `; %URL%`r`n`; `r`n%Clipboard%`r`n`r`n%Emergency_Exit%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
run, AHKscript.ahk
Return
+F12:: ; Shift+F12: Edit then run
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
FileAppend, `; %URL%`r`n`;`r`n%Clipboard%`r`n`r`n%Emergency_Exit%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
runwait, edit AHKscript.ahk
run, AHKscript.ahk
Return
!F12:: ; Alt+F12: Save last script
IfExist AHKscript.ahk
{
FileSelectFile, destination, S16, %A_Desktop%, Save Script:, Autohotkey Scripts (*.ahk)
If ERRORLEVEL
Msgbox, Script not saved.
Else
{
IfNotInString, destination, .ahk
destination = %destination%.ahk
FileCopy, AHKscript.ahk, %destination%, 1
}
}
Return
^#!r:: ; CTRL+Win+Alt+r: Reset THIS script if something goes wrong
Reload
Sleep, 5000
MsgBox, Unable to Reload Script
Return |
Further, can anyone suggest optimization that would make this script prettier to look at? _________________
SoggyDog
Download AutoHotKey Wallpaper
Does 'Fuzzy Logic' tickle? |
|
| Back to top |
|
 |
JSLover
Joined: 20 Dec 2004 Posts: 542 Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...
|
Posted: Sun Nov 12, 2006 11:19 pm Post subject: |
|
|
| jonny wrote: | Just remember to look at code before you run it..  |
...YES...my version...
- Checks for unsafe AHK commands
- Adds forum title & url to top of script as comment
- Can add any code before & after the tested script (for emergency exit hotkey, etc...)
- Prompts before ever running the script & after editing
- Prompts to delete temp script on exit
- Can change hotkey in top of script
...I still have more to edit on it, but this is the current version...
...keep checking for it to change... _________________
Home • Click image! • Blog |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Mon Nov 13, 2006 4:52 am Post subject: |
|
|
Nice! I really like the warning if a potentially dangerous command will be run.
I have two problems, though
1) when it grabbed the URL, it ended up grabbing the URL of the first tab in the firefox window, which was unrelated to the script forum. Not a big deal, and I don't know how to get the correct info from it (Auto It spy doesn't see anything except the first tab's URL in the Window text)
2) There is a very long message box with the code of the script. Again, I can't think of a good way to show the script without a large dialog, so for now, I have commented out
| Code: |
msgbox, 20, ,
(LTrim
-------------------
%TempScript%
-------------------
Run script now?
)
|
Otherwise your script is very useful (and running n my computer now!)
Thanks, _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
JSLover
Joined: 20 Dec 2004 Posts: 542 Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...
|
Posted: Mon Nov 13, 2006 6:19 am Post subject: |
|
|
| engunneer wrote: | | 1) when it grabbed the URL, it ended up grabbing the URL of the first tab in the firefox window... |
...ok, I only tested in Netscape 7.2 & IE 6.0...I still have some tricks to try...the next version will try harder to get the correct url...
| engunneer wrote: | | 2) There is a very long message box with the code of the script. |
...yes, in my Planned Features I mentioned GUI...I wanna replace that with a GUI & scrolling edit box...next version...
| engunneer wrote: | | ...so for now, I have commented out... |
...that msgbox asks a question...how did you comment it out without the answer always being no? You could change it to...
| Code: | msgbox, 20, ,
(LTrim
Run script now?
) |
...or...
| Code: | StringLeft, TempScript_view, TempScript, 3019
msgbox, 20, ,
(LTrim
-------------------
%TempScript_view%
-------------------
Run script now?
)
TempScript_view= |
| engunneer wrote: | | Otherwise your script is very useful (and running n my computer now!) |
...cool! _________________
Home • Click image! • Blog |
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 214 Location: Greeley, CO
|
Posted: Mon Dec 04, 2006 4:35 pm Post subject: |
|
|
Updated December 4, 2006
- Sometimes I just want to save a script without running it at all,
so I added CTRL+F12 to do that.
| Code: | ; =====================================================
; RUN | EDIT-RUN | SAVE HIGHLIGHTED SCRIPT FROM FORUM
; =====================================================
;
; Author: Shannon D Gerton - November 10, 2006; December 4, 2006
; Code snippets borrowed from Branden Gunn
; http://www.autohotkey.com/forum/viewtopic.php?p=88842
;
; ==========
; Hot Keys
; ==========
;
; F12: Run highlighted text as AHKscript.ahk.
;
; Shift+F12: Save highlighted text / open in your default editor.
; When the editor is closed, the script will start.
;
; Alt+F12: Open a dialog box to save the last temporary script.
; Automatically add an ahk extension if you forget to.
;
; CTRL+F12: Open a dialog box to save the highlighted script.
; Automatically add an ahk extension if you forget to.
; --Done WITHOUT running the script at all.
;
; CTRL+Win+Alt+r will Reset THIS script if something goes wrong.
;
; CTRL+Win+Alt+q is added to the copied script as an emergency exit.
;
; =====================================================
#SingleInstance
#NoTrayIcon
SetWorkingDir, %A_Temp%
ClipSaved =
Backdoor_Out = ^#!q::ExitApp `; DELETE - This line added by Script Capture System
F12:: ; F12 only: Run highlighted text
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
FileAppend, `; %URL%`r`n`; `r`n%Clipboard%`r`n`r`n%Backdoor_Out%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
run, AHKscript.ahk
Return
+F12:: ; Shift+F12: Edit then run
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
FileAppend, `; %URL%`r`n`;`r`n%Clipboard%`r`n`r`n%Backdoor_Out%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
runwait, edit AHKscript.ahk
run, AHKscript.ahk
Return
!F12:: ; Alt+F12: Save last script
IfExist AHKscript.ahk
{
FileSelectFile, destination, S16, %A_Desktop%, Save Script:, Autohotkey Scripts (*.ahk)
If ERRORLEVEL
Msgbox, Script not saved.
Else
{
IfNotInString, destination, .ahk
destination = %destination%.ahk
FileCopy, AHKscript.ahk, %destination%, 1
}
}
Return
^F12:: ; CTRL+F12: Save only
ControlGetText, URL, Edit1, ahk_class IEFrame
ClipSaved := ClipboardAll
Send, ^c
ifExist AHKscript.ahk
FileDelete AHKscript.ahk
FileAppend, `; %URL%`r`n`; `r`n%Clipboard%`r`n`r`n%Backdoor_Out%`r`n, AHKscript.ahk
Clipboard := ClipSaved
ClipSaved =
IfExist AHKscript.ahk
{
FileSelectFile, destination, S16, %A_Desktop%, Save Script:, Autohotkey Scripts (*.ahk)
If ERRORLEVEL
Msgbox, Script not saved.
Else
{
IfNotInString, destination, .ahk
destination = %destination%.ahk
FileCopy, AHKscript.ahk, %destination%, 1
}
}
Return
^#!r:: ; CTRL+Win+Alt+r: Reset THIS script if something goes wrong
Reload
Sleep, 5000
MsgBox, Unable to Reload Script
Return |
_________________
SoggyDog
Download AutoHotKey Wallpaper
Does 'Fuzzy Logic' tickle? |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Sun Dec 10, 2006 12:40 pm Post subject: |
|
|
| engunneer wrote: | | 1) when it grabbed the URL, it ended up grabbing the URL of the first tab in the firefox window, which was unrelated to the script forum. |
Try F4 / F6
Here's the code i'm using:
| Code: | ^+c::
SetWorkingDir, D:\My Documents\Settings\AutoHotkey\temp\
clipboard =
sleep 200
Send, ^c
;clipboard = %clipboard%
sleep 200
script = %clipboard%
SetTitleMatchMode, 2
IfWinActive,Mozilla Firefox
{
soundbeep, 1000, 100
Send {F6}
Send {CTRL Down}c{CTRL Up}
Send {F6}
sleep 200
URL = %clipboard%
}
IfWinActive, Internet Explorer
{
soundbeep, 2000, 100
sleep 100
soundbeep, 2000, 100
Send {F4}
Send, ^c
Send {F4}
sleep 200
URL = %clipboard%
}
WinGetActiveTitle, App
header1 = `;`n`; Automatically generated script`r`n`;`n
header2 = #NoEnv`r`n#singleinstance force`r`nsendmode Input`r`n`n`;---- copied script body ----`r`n`n
scriptname = %A_Now%.ahk
FileAppend, %header1%`; ..Copied from:`r`n; %URL%`r`n`; %App%`r`n`; On: %A_YYYY%.%A_MM%.%A_DD% %A_HOUR%:%A_MIN%:%A_SEC%`r`n`;`r`n%header2%%script%`r`n, %scriptname%
sleep 500
run, %scriptname%
run, edit %scriptname%
return
/* example - select the following line and hit ^+c
msgbox, %A_ScriptDir%\%A_ScriptName%
*/
|
and the output is:
| Code: | ;
; Automatically generated script
;
; ..Copied from:
; http://www.autohotkey.com/forum/viewtopic.php?p=93944#93944
; run scripts directly from the forum! - Mozilla Firefox
; On: 2006.12.13 06:16:28
;
#NoEnv
#singleinstance force
sendmode Input
;---- copied script body ----
msgbox, %A_ScriptDir%\%A_ScriptName% |
...not ideal, and YES you have to manually delete some files occasionally, but it works ok. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|