Page 1 of 1

(file) argument from terminal

Posted: Tue Dec 10, 2019 11:20 am
by Rinzwind
open -a TextEdit.app ~/Documents/mytext.txt

This works. Mind you, open -a TextEdit.app --args ~/Documents/mytext.txt does not work.

For PB programs only arguments passed with --args are seen with ProgramParameter. How do I get the access to the first one without --args? What's happening here?

Re: (file) argument from terminal

Posted: Tue Dec 10, 2019 1:29 pm
by wilbert
You have to use PB_Gadget_SetOpenFinderFiles.

Code: Select all

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0) ; Ensures the gadget lib is linked as this command is in it

ProcedureC OpenFinderFilesCallback(*Utf8Files)
  Protected Files.s = PeekS(*Utf8Files, -1, #PB_UTF8) ; Each file is separated by a 'tab'
  AddGadgetItem(0, -1, Files.s) ; Use StringField() to iterate easily
EndProcedure

OpenWindow(0, 0, 0, 820, 620, "OpenFinderFiles", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 800, 600)

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow