I made a simplified text translator, but I need to automatically send the selected text to the program window. It doesn't work very stable.
Code: Select all
Procedure Execute(comstr$)
Protected Pos, , Command$
comstr$ = LTrim(comstr$)
If Asc(comstr$)
Pos = FindString(comstr$ , " ")
If Pos
Command$ = Mid(comstr$, 1, Pos - 1)
If Not RunProgram(Command$, Mid(comstr$, Pos + 1), "", #PB_Program_Hide | #PB_Program_Wait)
MessageRequester("Error", "Failed to execute command " + Command$ + ". Check if this program is installed.")
EndIf
EndIf
EndIf
EndProcedure
Procedure Translate(Selected_Text$)
If RunProgram("bash", "-c " + Chr(34) + "xdotool search --name 'Google Translator' windowactivate %@" + Chr(34), "", #PB_Program_Open | #PB_Program_Read)
Delay(20)
SetClipboardText(Selected_Text$)
Delay(40)
Execute("xdotool key ctrl+a") ; hotkey - select all
Delay(20)
Execute("xdotool key delete") ; hotkey - delete (previously selected everything)
Delay(30)
Execute("xdotool key ctrl+v") ; hotkey - paste from clipboard
EndIf
EndProcedure