;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; AutoIt Version: 3.3.14.2 ;; ;; ;; ;; Template AutoIt script. ;; ;; ;; ;; AUTHOR: TheSaint ;; ;; ;; ;; SCRIPT FUNCTION: Program using a dropbox instead of the right-click open with menu ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; DropboxGUI(), SetupGUI() #include #include #include #include #include #include #include _Singleton("open-with-edit-thsaint") Global $Dropbox, $file, $inifle, $params, $path, $program, $setfle, $type, $updated, $version $inifle = @ScriptDir & "\Settings.ini" $setfle = @ScriptDir & "\Programs.ini" $updated = "(updated June 2023)" $version = "v1.0" DropboxGUI() Exit Func DropboxGUI() Local $Item_about, $Item_exit, $Item_file, $Item_fold, $Item_setup, $Label_drop, $Menu_drop ; Local $attrib, $fext, $left, $right, $target, $top, $winpos ; $right = @DesktopWidth - 87 $left = IniRead($inifle, "Dropbox Window", "left", $right) $top = IniRead($inifle, "Dropbox Window", "top", 27) $Dropbox = GuiCreate("Dropbox", 82, 90, $left, $top, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE _ + $WS_CLIPSIBLINGS, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW) ; $Label_drop = GUICtrlCreateLabel("", 0, 0, 80, 88, $SS_CENTER + $SS_NOTIFY) GUICtrlSetState($Label_drop, $GUI_DROPACCEPTED) GUICtrlSetFont($Label_drop, 8, 400) GUICtrlSetTip($Label_drop, "Drop a non executable File Here!") ; ; CONTEXT MENU $Menu_drop = GUICtrlCreateContextMenu($Label_drop) $Item_setup = GUICtrlCreateMenuItem("Open the Setup window", $Menu_drop) GUICtrlCreateMenuItem("", $Menu_drop) $Item_file = GUICtrlCreateMenuItem("View the Setup file", $Menu_drop) GUICtrlCreateMenuItem("", $Menu_drop) $Item_fold = GUICtrlCreateMenuItem("Open the program folder", $Menu_drop) GUICtrlCreateMenuItem("", $Menu_drop) $Item_about = GUICtrlCreateMenuItem("About", $Menu_drop) GUICtrlCreateMenuItem("", $Menu_drop) GUICtrlCreateMenuItem("", $Menu_drop) $Item_exit = GUICtrlCreateMenuItem("Exit the program", $Menu_drop) ; ; SETTINGS GUICtrlSetBkColor($Label_drop, $COLOR_LIME) $target = "Some" & @LF & "Right-Click" & @LF & "Options Are" & @LF & "Available" & @LF & "HERE" GUICtrlSetData($Label_drop, @LF & $target) Sleep(2000) GUICtrlSetBkColor($Label_drop, $CLR_DEFAULT) $target = "Drop A Text" & @LF & "Based File" & @LF & "HERE" & @LF & "(To Open In" & @LF & "An Editor)" GUICtrlSetData($Label_drop, @LF & $target) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Item_exit ; Close the Dropbox $winpos = WinGetPos($Dropbox, "") $left = $winpos[0] If $left < 0 Then $left = 2 ElseIf $left > @DesktopWidth - $winpos[2] Then $left = @DesktopWidth - $winpos[2] EndIf IniWrite($inifle, "Dropbox Window", "left", $left) $top = $winpos[1] If $top < 0 Then $top = 2 ElseIf $top > @DesktopHeight - $winpos[3] Then $top = @DesktopHeight - $winpos[3] EndIf IniWrite($inifle, "Dropbox Window", "top", $top) ; GUIDelete($Dropbox) ExitLoop Case $msg = $GUI_EVENT_DROPPED ; Folder added as new destination by drag and drop If @GUI_DragId = -1 Then If FileExists(@GUI_DragFile) Then $attrib = FileGetAttrib(@GUI_DragFile) If StringInStr($attrib, "D") > 0 Then MsgBox(262192, "Drag Error", "Needs to be a file not folder.", 0, $Dropbox) Else $path = @GUI_DragFile $file = StringSplit($path, "\", 1) $file = $file[$file[0]] $fext = StringSplit($file, ".", 1) $fext = $fext[$fext[0]] $fext = StringUpper($fext) If $fext = "EXE" Or $fext = "BAT" Or $fext = "COM" Then MsgBox(262192, "File Type Error", "Cannot be an executable file.", 0, $Dropbox) Else $program = IniRead($setfle, $fext, "path", "") If $program = "" Then SetupGUI($fext) Else $params = IniRead($setfle, $type, "params", "") ShellExecute($program, '"' & $path & '"', "", $params) EndIf EndIf EndIf Else MsgBox(262192, "Drag Error", "Drag & Drop path doesn't exist.", 0, $Dropbox) EndIf Else MsgBox(262192, "Drag Error", "Drag & Drop failed.", 0, $Dropbox) EndIf Case $msg = $Item_setup ; Open the Setup window SetupGUI("") Case $msg = $Item_fold ; Open the program folder ShellExecute(@ScriptDir) Case $msg = $Item_file ; Open the Setup file If FileExists($setfle) Then ShellExecute($setfle) Case $msg = $Item_about ; About the program MsgBox(262208, "About The Program", _ "This is an assistant program to help with running" & @LF & _ "the selected (dropped) file in a specified Editor." & @LF & @LF & _ "Unknown files will present a Setup window, while" & @LF & _ "known files will automatically open in an editor." & @LF & @LF & _ "Click the Drag & Drop area for the Setup window." & @LF & @LF & _ "BIG THANKS to Jon & team at the AutoIt Forum." & @LF & @LF & _ "© June 2023 by TheSaint - Open With Edit " & $version & @LF & _ $updated, 0, $Dropbox) Case $msg = $Label_drop ; Open the Setup window GUISetState(@SW_HIDE, $Dropbox) SetupGUI("") GUIDelete($Dropbox) ExitLoop Case Else ;;; EndSelect WEnd EndFunc ;=> DropboxGUI Func SetupGUI($type) Local $Button_add, $Button_browse, $Button_fold, $Button_info, $Button_last, $Button_quit, $Button_remove Local $Button_test, $Combo_type, $Group_programs, $Input_name, $Input_params, $Input_program, $Label_name Local $Label_params, $Label_program, $Label_type ; Local $changed, $icoD, $icoI, $icoR, $icoX, $name, $ProgramsGUI, $pth, $shell, $style, $types, $user32 ; $style = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_CLIPSIBLINGS, $WS_VISIBLE, $WS_MINIMIZEBOX) $ProgramsGUI = GuiCreate("Program Setup", 420, 185, -1, -1, $style, $WS_EX_TOPMOST, $Dropbox) GUISetBkColor($COLOR_SKYBLUE, $ProgramsGUI) ; ; CONTROLS $Group_programs = GuiCtrlCreateGroup("Programs", 10, 10, 400, 105) $Label_type = GUICtrlCreateLabel("File Type", 20, 30, 65, 21, $SS_CENTER + $SS_CENTERIMAGE + $SS_SUNKEN) GUICtrlSetFont($Label_type, 7, 600, 0, "Small Fonts") GUICtrlSetBkColor($Label_type, $COLOR_BLACK) GUICtrlSetColor($Label_type, $COLOR_WHITE) $Combo_type = GUICtrlCreateCombo("", 85, 30, 55, 21, $GUI_SS_DEFAULT_COMBO + $CBS_SORT) GUICtrlSetTip($Combo_type, "Selected file type!") $Label_name = GUICtrlCreateLabel("Program Name", 150, 30, 95, 21, $SS_CENTER + $SS_CENTERIMAGE + $SS_SUNKEN) GUICtrlSetFont($Label_name, 7, 600, 0, "Small Fonts") GUICtrlSetBkColor($Label_name, $COLOR_GREEN) GUICtrlSetColor($Label_name, $COLOR_WHITE) $Input_name = GUICtrlCreateInput("", 245, 30, 155, 21) GUICtrlSetTip($Input_name, "Selected program name!") $Label_program = GUICtrlCreateLabel("Program Path", 20, 56, 90, 20, $SS_CENTER + $SS_CENTERIMAGE + $SS_SUNKEN) GUICtrlSetFont($Label_program, 7, 600, 0, "Small Fonts") GUICtrlSetBkColor($Label_program, $COLOR_BLUE) GUICtrlSetColor($Label_program, $COLOR_WHITE) $Input_program = GUICtrlCreateInput("", 110, 56, 290, 20) GUICtrlSetTip($Input_program, "Program path for selected file type!") $Label_params = GUICtrlCreateLabel("Parameters", 20, 81, 80, 20, $SS_CENTER + $SS_CENTERIMAGE + $SS_SUNKEN) GUICtrlSetFont($Label_params, 7, 600, 0, "Small Fonts") GUICtrlSetBkColor($Label_params, $COLOR_RED) GUICtrlSetColor($Label_params, $COLOR_WHITE) $Input_params = GUICtrlCreateInput("", 100, 81, 155, 20) GUICtrlSetTip($Input_params, "Parameters for selected program (if needed)!") $Button_last = GuiCtrlCreateButton("LAST", 265, 80, 55, 23) GUICtrlSetFont($Button_last, 7, 600, 0, "Small Fonts") GUICtrlSetTip($Button_last, "Select the last added program!") $Button_browse = GuiCtrlCreateButton("BROWSE", 330, 80, 70, 23) GUICtrlSetFont($Button_browse, 7, 600, 0, "Small Fonts") GUICtrlSetTip($Button_browse, "Browse to select a program!") ; $Button_test = GuiCtrlCreateButton("D", 10, 125, 50, 50, $BS_ICON) GUICtrlSetTip($Button_test, "Test run the program and file!") ; $Button_add = GuiCtrlCreateButton("ADD", 70, 125, 60, 50) GUICtrlSetFont($Button_add, 9, 600) GUICtrlSetTip($Button_add, "ADD a specific file type!") ; $Button_remove = GuiCtrlCreateButton("REMOVE", 140, 125, 90, 50) GUICtrlSetFont($Button_remove, 9, 600) GUICtrlSetTip($Button_remove, "Remove a specific file type!") ; $Button_fold = GuiCtrlCreateButton("D", 240, 125, 50, 50, $BS_ICON) GUICtrlSetTip($Button_fold, "Open the program folder!") ; $Button_info = GuiCtrlCreateButton("Info", 300, 125, 50, 50, $BS_ICON) GUICtrlSetTip($Button_info, "Viewer Information!") ; $Button_quit = GuiCtrlCreateButton("EXIT", 360, 125, 50, 50, $BS_ICON) GUICtrlSetTip($Button_quit, "Exit / Close / Quit the window!") ; ; OS SETTINGS $user32 = @SystemDir & "\user32.dll" $shell = @SystemDir & "\shell32.dll" $icoD = -4 $icoI = -5 $icoR = -138 $icoX = -4 ; ; SETTINGS GUICtrlSetImage($Button_test, $shell, $icoR, 1) GUICtrlSetImage($Button_fold, $shell, $icoD, 1) GUICtrlSetImage($Button_info, $user32, $icoI, 1) GUICtrlSetImage($Button_quit, $user32, $icoX, 1) ; $types = IniRead($inifle, "File", "types", "") If $types = "" Then $types = "||" IniWrite($inifle, "File", "types", $types) EndIf If $type = "" Then GUICtrlSetState($Button_test, $GUI_DISABLE) ; $type = IniRead($inifle, "File", "type", "") GUICtrlSetData($Combo_type, $types, $type) If $type <> "" Then $program = IniRead($setfle, $type, "path", "") If $program <> "" Then GUICtrlSetData($Input_program, $program) $name = IniRead($setfle, $type, "name", "") GUICtrlSetData($Input_name, $name) $params = IniRead($setfle, $type, "params", "") If $params <> "" Then GUICtrlSetData($Input_params, $params) EndIf EndIf Else GUICtrlSetData($Combo_type, $types & "|" & $type, $type) EndIf GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_quit ; Close the Setup window GUIDelete($ProgramsGUI) ExitLoop Case $msg = $Button_test ; Test run the program and file If FileExists($program) Then If FileExists($path) Then ShellExecute($program, '"' & $path & '"', "", $params) Else MsgBox(262192, "Source Error", "The dropped file path does not exist.", 0, $ProgramsGUI) EndIf Else MsgBox(262192, "RUN Error", "The program path does not exist.", 0, $ProgramsGUI) EndIf Case $msg = $Button_remove ; Remove a specific file type $type = GUICtrlRead($Combo_type) If $type = "" Then MsgBox(262192, "Removal Error", "No file type selected.", 0, $ProgramsGUI) Else If StringInStr($types, "|" & $type & "|") > 0 Then $types = StringReplace($types, "|" & $type & "|", "|") IniWrite($inifle, "File", "types", $types) $program = IniRead($setfle, $type, "path", "") If $program <> "" Then IniDelete($setfle, $type) $program = "" GUICtrlSetData($Input_program, $program) $name = "" GUICtrlSetData($Input_name, $name) $params = "" GUICtrlSetData($Input_params, $params) EndIf $type = "" IniWrite($inifle, "File", "type", $type) GUICtrlSetData($Combo_type, "", "") GUICtrlSetData($Combo_type, $types, $type) Else MsgBox(262192, "Remove Error", "File type doesn't exist.", 0, $ProgramsGUI) EndIf EndIf Case $msg = $Button_last ; Select the last added program If $type = "" Then MsgBox(262192, "Retrieve Error", "No file type selected.", 0, $ProgramsGUI) Else $program = IniRead($inifle, "Last Program", "path", "") ;IniWrite($setfle, $type, "path", $program) GUICtrlSetData($Input_program, $program) $name = IniRead($inifle, "Last Program", "name", "") ;IniWrite($setfle, $type, "name", $name) GUICtrlSetData($Input_name, $name) $params = IniRead($inifle, "Last Program", "params", "") ;IniWrite($setfle, $type, "params", $params) GUICtrlSetData($Input_params, $params) EndIf Case $msg = $Button_info ; Setup Information MsgBox(262208, "About The Program", _ "This is an assistant program to help with running" & @LF & _ "the selected (dropped) file in a specified Editor." & @LF & @LF & _ "Unknown files will present a Setup window, while" & @LF & _ "known files will automatically open in an editor." & @LF & @LF & _ "Click the Drag & Drop area for the Setup window." & @LF & @LF & _ "[Setup Usage]" & @LF & _ "You don't need to use the ADD button if you just" & @LF & _ "browse for and select the program to use for the" & @LF & _ "currently selected file type (extension)." & @LF & _ "The ADD button can be used to make changes to" & @LF & _ "the Program Name or Parameters, or to just ADD" & @LF & _ "all the elements manually in stages." & @LF & @LF & _ "Depending on a dropped source file or program," & @LF & _ "you may not need to specify any parameters." & @LF & @LF & _ "If you want, you can use the TEST button to run" & @LF & _ "the selected file with its specified program etc." & @LF & @LF & _ "Use the ADD button after using the LAST button" & @LF & _ "to save the retrieved values for selected file type." & @LF & @LF & _ "The REMOVE button removes selected file type" & @LF & _ "and associated program values." & @LF & @LF & _ "BIG THANKS to Jon & team at the AutoIt Forum." & @LF & @LF & _ "© June 2023 by TheSaint - Open With Edit " & $version & @LF & _ $updated, 0, $Dropbox) Case $msg = $Button_fold ; Open the program folder ShellExecute(@ScriptDir) Case $msg = $Button_browse ; Browse to select a program $type = GUICtrlRead($Combo_type) If $type = "" Then MsgBox(262192, "Browse Error", "Select a file type first.", 0, $ProgramsGUI) ElseIf $type = "EXE" Or $type = "BAT" Or $type = "COM" Then MsgBox(262192, "ADD Error", "Cannot specify an executable program file.", 0, $ProgramsGUI) Else $pth = FileOpenDialog("Select a program to use for selected file type.", @ProgramFilesDir, "Program Files (*.exe)", 3, "", $ProgramsGUI) If Not @error Then $program = $pth IniWrite($setfle, $type, "path", $program) GUICtrlSetData($Input_program, $program) $name = StringSplit($program, "\", 1) $name = $name[$name[0]] $name = StringSplit($name, ".", 1) $name = $name[1] IniWrite($setfle, $type, "name", $name) GUICtrlSetData($Input_name, $name) $params = "" IniWrite($setfle, $type, "params", $params) GUICtrlSetData($Input_params, $params) ; IniWrite($inifle, "Last Program", "path", $program) IniWrite($inifle, "Last Program", "name", $name) IniWrite($inifle, "Last Program", "params", $params) ; If StringInStr($types, "|" & $type & "|") < 1 Then $types = $types & $type & "|" IniWrite($inifle, "File", "types", $types) IniWrite($inifle, "File", "type", $type) GUICtrlSetData($Combo_type, "", "") GUICtrlSetData($Combo_type, $types, $type) EndIf EndIf EndIf Case $msg = $Button_add ; ADD a specific file type $type = GUICtrlRead($Combo_type) If $type = "" Then MsgBox(262192, "ADD Error", "No file type specified.", 0, $ProgramsGUI) ElseIf $type = "EXE" Or $type = "BAT" Or $type = "COM" Then MsgBox(262192, "ADD Error", "Cannot specify an executable program file.", 0, $ProgramsGUI) Else If StringInStr($types, "|" & $type & "|") < 1 Then $types = $types & $type & "|" IniWrite($inifle, "File", "types", $types) IniWrite($inifle, "File", "type", $type) GUICtrlSetData($Combo_type, "", "") GUICtrlSetData($Combo_type, $types, $type) EndIf If $type <> "" Then $changed = "" $program = GUICtrlRead($Input_program) If $program <> IniRead($setfle, $type, "path", "") Then If FileExists($program) Then IniWrite($setfle, $type, "path", $program) $changed = 1 Else MsgBox(262192, "ADD Error", "The program path does not exist.", 0, $ProgramsGUI) EndIf EndIf $name = GUICtrlRead($Input_name) If $name <> IniRead($setfle, $type, "name", "") Then IniWrite($setfle, $type, "name", $name) $changed = 1 EndIf $params = GUICtrlRead($Input_params) If $params <> IniRead($setfle, $type, "params", "") Then IniWrite($setfle, $type, "params", $params) $changed = 1 EndIf If $changed = "" Then MsgBox(262192, "ADD Error", "File type already exists.", 0, $ProgramsGUI) EndIf EndIf EndIf Case $msg = $Combo_type ; Selected file type $type = GUICtrlRead($Combo_type) $program = IniRead($setfle, $type, "path", "") If $program = "" Then $name = "" $params = "" Else $name = IniRead($setfle, $type, "name", "") $params = IniRead($setfle, $type, "params", "") EndIf GUICtrlSetData($Input_name, $name) GUICtrlSetData($Input_program, $program) GUICtrlSetData($Input_params, $params) Case Else ;;; EndSelect WEnd EndFunc ;=> SetupGUI