Jump to content

Get File+Path from Notepad's Open File Dialog


Recommended Posts

Greetings,

My apologies if this question is too easy, repetitive, or if this is the wrong place to ask. I'm a noob to AutoIT.

I'm working on a script that opens (for example) notepad followed by the Open File dialog ( Send ("^o") ). When a file is selected, and the Open button pressed, the file and it's path are returned to notepad. Is it possible to capture that Path\File information to my script?

If anyone could post some code, that would be helpful, but really all I need is for someone to point me to the some functions. I could look up their usage from the help file.

Thank You.

Link to comment
Share on other sites

Hi Ephesian,

3 hours ago, Ephesian said:

I'm working on a script that opens (for example) notepad followed by the Open File dialog ( Send ("^o") ).

What have you've got so far?

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

@Ephesian,

Is this what you need?^_^

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Run Notepad with the window maximized.
    Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

   ; Wait 2 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 2)
    Local $sFileOpenDialog = FileOpenDialog("Test", @WindowsDir & "\", "Text Document (*.txt)")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
   MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)

   EndIf
   Send($sFileOpenDialog)
   sleep(2000)
   ProcessClose($iPID)
EndFunc   ;==>Example

 

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

6 hours ago, KickStarter15 said:

@Ephesian,

Is this what you need?^_^

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Run Notepad with the window maximized.
    Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

   ; Wait 2 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 2)
    Local $sFileOpenDialog = FileOpenDialog("Test", @WindowsDir & "\", "Text Document (*.txt)")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
   MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)

   EndIf
   Send($sFileOpenDialog)
   sleep(2000)
   ProcessClose($iPID)
EndFunc   ;==>Example

Thank You, KickStarter15. The script works well, and answered several questions I had. But I should probably clarify. It's not really Notepad I'm using, but a software sampler called VSampler3.  The line in your example...

Local $sFileOpenDialog = FileOpenDialog("Test", @WindowsDir & "\", "Text Document (*.txt)")

... seems to open the script's own File Open dialog, not notepad's. It wasn't obvious to me at first until I tried it in VSampler3.

When I ran the script with VSampler3 a dialog does appear, but the selected file (.VS3) doesn't load into VSampler. What I'm trying to automate is the opening of VSampler3, Select the open file dialog to load a .VS3 file into the program , and obtain the selected file's path at the same time.

HOWEVER, I believe I found a way to do it using your method instead. Which I think would be better anyway. Rather than running VSampler first,:
1) Create an Open File dialog, 2) Select the file, 3) Obtain the path, 4) Use the Path in the target of VSampler3 to start the program with the VS3 file. I believe this might be a more efficient way of doing it actually. So Thank You for your ideas. The were of great help.

Thank You much

6 hours ago, KickStarter15 said:

 

 

Edited by Ephesian
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...