Overcoming limitation browsing for .app files

Mac OSX specific forum
P-J
User
User
Posts: 44
Joined: Fri Jan 23, 2004 6:54 pm
Contact:

Overcoming limitation browsing for .app files

Post by P-J »

Hi there,

I've read in this forum that it's not possible to browse for .app files since they're seen as a folder and not a file.

I'm writing a program which needs the user to browse for an executable (to 'locate it'), and then to run this executable. Is there any way to do this in Purebasic without resorting to manually entering in the path?

Any help much appreciated!

Thanks, Phil.
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Overcoming limitation browsing for .app files

Post by WilliamL »

Where did you read that! :shock:

Look in the Help file for 'Filename$ = OpenFileRequester(Title$, DefaultFile$, Pattern$, PatternPosition [, Flags])'. Be aware that 'Pattern$' does not work on the Mac. This command will bring up the Mac load/save window and will let you navigate to the app and return the full path in Filename$

You might be interested in GetPathPart and GetFilePart for separating the Filename$ into it parts (path/app).
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
P-J
User
User
Posts: 44
Joined: Fri Jan 23, 2004 6:54 pm
Contact:

Re: Overcoming limitation browsing for .app files

Post by P-J »

WilliamL wrote:Where did you read that! :shock:
I was a good boy and did a search for this earlier, and came across a thread that suggested it wasn't possible :?:
WilliamL wrote: Look in the Help file for 'Filename$ = OpenFileRequester(Title$, DefaultFile$, Pattern$, PatternPosition [, Flags])'. Be aware that 'Pattern$' does not work on the Mac. This command will bring up the Mac load/save window and will let you navigate to the app and return the full path in Filename$

You might be interested in GetPathPart and GetFilePart for separating the Filename$ into it parts (path/app).
This is where the problem lies-- When using OpenFileRequester(), all the .app files (well, folders) are greyed out and so aren't selectable. Is there anyway round this?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Overcoming limitation browsing for .app files

Post by wilbert »

.app files aren't executables.
They are an archive containing multiple files like a .zip file.
If you click on an .app file with the right mouse button in the Finder application, you can show the contents of the package.
P-J
User
User
Posts: 44
Joined: Fri Jan 23, 2004 6:54 pm
Contact:

Re: Overcoming limitation browsing for .app files

Post by P-J »

wilbert wrote:.app files aren't executables.
They are an archive containing multiple files like a .zip file.
If you click on an .app file with the right mouse button in the Finder application, you can show the contents of the package.
I know they aren't executables dude.

Are you saying that a user should be able to right-click them in the Purebasic OpenFileRequester() dialog and open the contents? It ain't working for me...

Anyone know of any method that would allow a user to browse to a program (that will later be executed) using the built-in requester tools?

Cheers.
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Overcoming limitation browsing for .app files

Post by WilliamL »

What we have here is a failure to communicate! :wink: (Hi, Wilbert, how's it going?)

No, I don't know any way to select an app from the requester tool.

There is a folder requester 'Filename$ = PathRequester(Title$, InitialPath$)' that will give you a path and that's about it.

...I guess if I had understood the question better (my fault) I wouldn't have posted.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Overcoming limitation browsing for .app files

Post by wilbert »

.app files are probably hidden files.
There are some suggestions on the internet on how to show them but I can't get them working myself.
Just google for
display hidden files open dialog osx
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Overcoming limitation browsing for .app files

Post by Polo »

wilbert wrote:.app files are probably hidden files.
There are some suggestions on the internet on how to show them but I can't get them working myself.
Just google for
display hidden files open dialog osx
It's not an hidden file, it's a folder named Application.app :)
spacebuddy
Enthusiast
Enthusiast
Posts: 356
Joined: Thu Jul 02, 2009 5:42 am

Re: Overcoming limitation browsing for .app files

Post by spacebuddy »

This is a bug in PureBasic. :cry:

If you use any other language, Xcode, Realbasic it works properly
and returns the path and filename of the application.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Overcoming limitation browsing for .app files

Post by Shardik »

You may try this workaround to display a list of apps. After you double click
onto an app it will be started:

Code: Select all

OpenWindow(0, 270, 100, 270, 170, "Double click on app to start it")
ListViewGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)

If ExamineDirectory(0, "/Applications", "")
  While NextDirectoryEntry(0)
    If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory
      If LCase(Right(DirectoryEntryName(0), 4)) = ".app"
        AddGadgetItem(0, -1, DirectoryEntryName(0))
      EndIf
    EndIf
  Wend
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 0
        If EventType() = #PB_EventType_LeftDoubleClick
          RunProgram("Open", "/Applications/" + GetGadgetText(0), "", #PB_Program_Open)
        EndIf
      EndIf
  EndSelect
ForEver
Another workaround would be to utilize the ExplorerTreeGadget (if you don't
mind double clicking onto the virtual app folder to start the app):

Code: Select all

OpenWindow(0, 270, 100, 270, 270, "Double click on app to start it")
ExplorerTreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "/Applications/")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 0
        If EventType() = #PB_EventType_LeftDoubleClick
          RunProgram("Open", GetGadgetText(0), "", #PB_Program_Open)
        EndIf
      EndIf
  EndSelect
ForEver
P-J
User
User
Posts: 44
Joined: Fri Jan 23, 2004 6:54 pm
Contact:

Re: Overcoming limitation browsing for .app files

Post by P-J »

Thanks for the suggestion above. I'll certainly give it a go.

I was hoping to have seamless cross-platform functionality (using native file browsers), but if this works it'll certainly do for now!
Post Reply