(file) argument from terminal

Mac OSX specific forum
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

(file) argument from terminal

Post 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?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: (file) argument from terminal

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply