Page 1 of 1
Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 2:33 am
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.
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 4:55 am
by WilliamL
Where did you read that!
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).
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 10:37 am
by P-J
WilliamL wrote:Where did you read that!
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?
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 11:18 am
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.
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 11:30 am
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.
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 6:07 pm
by WilliamL
What we have here is a failure to communicate!

(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.
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 6:43 pm
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
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 6:57 pm
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

Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 7:59 pm
by spacebuddy
This is a bug in PureBasic.
If you use any other language, Xcode, Realbasic it works properly
and returns the path and filename of the application.
Re: Overcoming limitation browsing for .app files
Posted: Wed Feb 29, 2012 9:18 pm
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
Re: Overcoming limitation browsing for .app files
Posted: Thu Mar 01, 2012 1:05 pm
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!