Jump to content

Run (and maybe save) posted scripts


Steph
 Share

Recommended Posts

As a relative newcomer to AutoIt I like trying out the scripts I see here, but got fed copying, pasting, saving and running. "Ah-ha" I thought ...

The idea is you select and copy the script to the clipboard and then hit Ctrl-r to run or Alt-r to save and then run.

Two problems you might be able to help with - I wanted to send Ctrl-C to copy the selected text to the clipboard automatically, but the window with the selected text on looses the focus, how do I find which window was active when the hotkey was pressed? The second is that the save dialogue doesn't appear on top. All ideas gratefully received.

HotKeySet("^r","RunScript")
HotKeySet("!r","SaveAndRunScript")

While 1
    Sleep(100)
WEnd

Func RunScript()
    DoSaveAndRun(@tempdir & "\TempScript.au3")
EndFunc

Func SaveAndRunScript()
    $File=FileSaveDialog("Save AutoIt File", @MyDocumentsDir, "Scripts (*.au3)", 16, "*.au3")
    if @error=0 Then
        DoSaveAndRun($File)
    EndIf
EndFunc

Func DoSaveAndRun($FileName)
    $Script=ClipGet()
    $Handle=FileOpen($FileName, 2)
    FileWrite($Handle,$Script)
    FileClose($Handle)
    Run("AutoIt3" & ' "' & $FileName & '"')
EndFunc
Link to comment
Share on other sites

http://www.autoitscript.com/forum/index.ph...wtopic=6421&hl=

There was an issue with ClipGet() if the clipboard changes while the script is open. Try your script and make sure it can run multiple scripts while it's still running.

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

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
 Share

  • Recently Browsing   0 members

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