DoBrowse to automatically popup a browse-for-file dialog

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

DoBrowse to automatically popup a browse-for-file dialog

Post by Grovkillen » Wed May 15, 2024 4:18 pm

I have not come to be a friend of the Input command since it's not very configurable and most of the time I just want to use it for adding a file path to the running script. I have come up with this little hack to make it more stream line.

Code: Select all

Let>WIN_USEHANDLE=1

Dialog>BrowseButtonDialog
object BrowseButtonDialog: TForm
  Caption = 'BrowseButtonDialog'
  ClientHeight = 1
  ClientWidth = 1
  object BrowseButton: tMSButton
    Left = 0
    Top = 0
    Width = 1
    Height = 1
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>BrowseButtonDialog

MoveWindow>BrowseButtonDialog.HANDLE,-9999,-9999
Let>TEMP_file_name=
Show>BrowseButtonDialog
SetDialogProperty>BrowseButtonDialog,BrowseButton,DoBrowse,True
GetDialogProperty>BrowseButtonDialog,BrowseButton,FileName,TEMP_file_name
SetDialogProperty>BrowseButtonDialog,BrowseButton,DoBrowse,False
CloseDialog>BrowseButtonDialog

MDL>TEMP_file_name
Whenever I need to fetch a file path I just run these lines:

Code: Select all

Let>TEMP_file_name=
Show>BrowseButtonDialog
SetDialogProperty>BrowseButtonDialog,BrowseButton,DoBrowse,True
GetDialogProperty>BrowseButtonDialog,BrowseButton,FileName,TEMP_file_name
SetDialogProperty>BrowseButtonDialog,BrowseButton,DoBrowse,False
CloseDialog>BrowseButtonDialog
If the "TEMP_file_name" is empty it means that the input of a file path was canceled.
Last edited by Grovkillen on Thu May 16, 2024 7:25 am, edited 2 times in total.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: DoBrowse to automatically popup a browse-for-file dialog

Post by Grovkillen » Wed May 15, 2024 4:43 pm

And here's one with a filter:

Code: Select all


Let>WIN_USEHANDLE=1

Dialog>BrowseButtonDialog
object BrowseButtonDialog: TForm
  Caption = 'BrowseButtonDialog'
  ClientHeight = 1
  ClientWidth = 1
  object BrowseButton: tMSButton
    Left = 0
    Top = 0
    Width = 1
    Height = 1
    TabOrder = 0
    DoBrowse = False
    Filter = 'Text files|*.scp;*.txt|All Files|*.*'
  end
end
EndDialog>BrowseButtonDialog

MoveWindow>BrowseButtonDialog.HANDLE,-9999,-9999

Let>TEMP_file_name=
Show>BrowseButtonDialog
SetDialogProperty>BrowseButtonDialog,BrowseButton,DoBrowse,True
GetDialogProperty>BrowseButtonDialog,BrowseButton,FileName,TEMP_file_name
SetDialogProperty>BrowseButtonDialog,BrowseButton,DoBrowse,False
CloseDialog>BrowseButtonDialog

MDL>TEMP_file_name
You may also use the InitialDir to set the folder which should be selected upon browse.
Let>ME=%Script%

Running: 15.0.27
version history

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts