; Module/File: System_DefaultApplicationRead+Open.pb ; Function: Reads default application and opens filetype with it - Linux ; Author: Omi ; Date: Dec. 19, 2014 ; Version: 0.2; update for (K)ubuntu ; Target Compiler: PureBasic 5.22/5.31 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- ;If opened with xdg-open, you get the ProgramId from xdg-open and can't communicate with the application ;Here's a way to read the standard application for f.e. a txt-file and opens it directly for read, write, kill, ... Global.s gAppName, FType ="application/pdf" ;replace with existing pdf-file ... Global.s gFile= "/home/charly-xubuntu/Programming/PBSource/ComTool/COM-Tool.pdf" Global.i ExtFound Debug "Default-Application (pdf)..." ;get application ... ProgramID= RunProgram("xdg-mime", " query default " + #DQUOTE$ + FType + #DQUOTE$, "", #PB_Program_Open | #PB_Program_Read) While ProgramRunning(ProgramID) If AvailableProgramOutput(ProgramID) gAppName + ReadProgramString(ProgramID) EndIf Wend CloseProgram(ProgramID) Debug "application/pdf: " + gAppName ;extract programname If FindString(gAppName, ".desktop") gAppName= StringField(gAppName, 1, "."); cut '.desktop' ;cut extension for KDE-format ... ReplaceString(FType, "/", "_", #PB_String_InPlace); cut extended formats like 'evinceapplication_pdf.desktop' ExtFound= FindString(LCase(gAppName), FType) If ExtFound gAppName= Left(gAppName, ExtFound- 1); pure app-name f.e. 'evince' EndIf If Left(gAppName, 5)= "kde4-"; kill prefix 'kde-4' gAppName= Mid(gAppName, 6) EndIf EndIf Debug "open pdf-file with: " + gAppName ProgramID= RunProgram(gAppName, #DQUOTE$ + gFile + #DQUOTE$, "", #PB_Program_Open) Debug "wait 8 seconds and do nothing ..." Delay(8000) If ProgramID Debug "now kill " + gAppName KillProgram(ProgramID) CloseProgram(ProgramID) EndIf ; IDE Options = PureBasic 5.40 LTS Beta 9 (Linux - x86) ; CursorPosition = 16 ; EnableUnicode ; EnableXP