Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSTask/NSTask with Arguments
Function:
Required plugins for this example: MBS MacCocoa Plugin, MBS MacOSX Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSTask/NSTask with Arguments
This example is the version from Mon, 11th Dec 2016.
Project "NSTask with Arguments.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // create folder with dummy images Dim I , Size As Integer Dim FramePicture As New Picture( 256 , 256 ) dim g as Graphics = FramePicture.Graphics dim folder as FolderItem = SpecialFolder.Desktop.Child( "NStask Frames" ) folder.CreateAsFolder For I = 1 To 48 Size = 32 + I g.ForeColor = RGB( 0, 0 , 0 ) g.FillRect ( 0 , 0 , 256 , 256 ) g.ForeColor = RGB( 255 , 255 , 0 ) g.FillRect( 128 - Size , 128 - Size , 2 * Size , 2 * Size ) FramePicture.Save( folder.Child( "Viz" + Format( I , "00" ) + ".png" ) , Picture.SaveAsPNG ) Next End EventHandler
Note "Readme"
This example runs ffmpeg and is sandbox able. So please download ffmpeg and put in same folder as app. http://www.ffmpegmac.net Example with help from James (bailey1660@verizon.net)
End Class
Class Window1 Inherits Window
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Dim FramesNativePath, ExecutableNativePath As String #if RBVersion < 2013 then FramesNativePath = SpecialFolder.desktop.Child( "NStask Frames" ).UnixpathMBS If DebugBuild Then ExecutableNativePath = GetFolderItem( "ffmpeg" ).UnixpathMBS Else dim a as FolderItem = app.ExecutableFile.parent.Child( "ffmpeg" ) If a.Exists Then ExecutableNativePath = a.UnixpathMBS Else MsgBox "Remember to move ffmpeg into the MacOS subfolder." Quit End if End if #else FramesNativePath = SpecialFolder.desktop.Child( "NStask Frames" ).NativePath If DebugBuild Then ExecutableNativePath = GetFolderItem( "ffmpeg" ).NativePath Else dim a as FolderItem = app.ExecutableFile.parent.Child( "ffmpeg" ) If a.Exists Then ExecutableNativePath = a.NativePath Else MsgBox "Remember to move ffmpeg into the MacOS subfolder." Quit End if End if #endif outputPipe = new NSPipeMBS task = new MyTask Dim Arguments( -1 ) As String // *** using full paths *** 'Arguments.Append "-i" 'Arguments.Append FramesNativePath + "/Viz%02d.png" 'Arguments.Append "-f" 'Arguments.Append "mp4" 'Arguments.Append "-vcodec" 'Arguments.Append "libx264" 'Arguments.Append "-pix_fmt" 'Arguments.Append "yuv420p" 'Arguments.Append FramesNativePath + "/Movie.mp4" // *** using currentDirectoryPath *** task.currentDirectoryPath = FramesNativePath Arguments.Append "-i" Arguments.Append "Viz%02d.png" Arguments.Append "-f" Arguments.Append "mp4" Arguments.Append "-vcodec" Arguments.Append "libx264" Arguments.Append "-pix_fmt" Arguments.Append "yuv420p" Arguments.Append "Movie.mp4" //********************************** task.setArguments Arguments() task.setStandardOutput outputPipe task.setStandardError outputPipe task.launchPath = ExecutableNativePath task.launch outputHandle = outputPipe.fileHandleForReading // async 'return // syncronously task.waitUntilExit finish 'Quit End EventHandler
End Control
Sub Finish() dim data as MemoryBlock = outputHandle.readDataOfLength(outputHandle.AvailableBytes) if data <> nil then dim s as string = DefineEncoding(data, encodings.UTF8) s = ReplaceLineEndings(s, EndOfLine) TextArea1.Text = s end if End Sub
Property outputHandle As NSFileHandleMBS
Property outputPipe As NSPipeMBS
Property task As MyTask
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyTask Inherits NSTaskMBS
EventHandler Sub Terminated() MsgBox "terminated." window1.Finish End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.




Links
MBS Xojo Plugins