RunProgram() Again!

Mac OSX specific forum
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

RunProgram() Again!

Post by collectordave »

Searched forum tried all the tips but still cannot get this to work.

I have tried both of these

Code: Select all

   Debug RunProgram(GetUserDirectory(#PB_Directory_Programs)  + "WSCHelp.app/Contents/MacOS/WSCHelp","","")
   Debug  RunProgram(GetUserDirectory(#PB_Directory_Programs)  + "WSCHelp","","")
The second with and without the .app.

The program launches perfectly within launcher and also if I use finder just not with PB???

CD

PS Moved app to same folder as prog and ran

Code: Select all

Debug RunProgram("Open","WSCHelp.app","")
and it works but if I specify the path it doesn't?

PPS

Added Chr(34) to start and end of the path including app name and it works when in the application folder however

Specifying this to run the copy in the applications folder:

Code: Select all

 
 Folder.s = GetUserDirectory(#PB_Directory_Programs)  + "WSCHelp.app"
  Debug  RunProgram("Open",Chr(34) + Folder + Chr(34),"")
Does Not Work???
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: RunProgram() Again!

Post by Wolfram »

Are you sure your program is in "/Users/YOURNAME/Applications" ?
Normally the programs are in "/Applications".
macOS Catalina 10.15.7
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: RunProgram() Again!

Post by collectordave »

Now that is a bit weird.

Using finder it appears to be in /Applications and in username/Applications

A little further on it appears that the Applications in UserName could be a shortcut.

If so looking for in a shortcut is no good.

However GetUserDirectory for programmes returns this directory(short cut) as the path.

Removing the Username bit gets it to work.

Code: Select all

RunProgram("Open",Chr(34) + "/Applications/WSCHelp.app" + Chr(34),"")
Works.

Could ask that this is pointed out in the PB docs as get userdirectory in this case does not return a directory.

Thanks for the pointer.

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: RunProgram() Again!

Post by collectordave »

Just another puzzle with run program

Code: Select all

 
   FileToEdit = "Main Form.html"
  ;RunProgram("/Applications/KompoZer.app ","--args " + Chr(34)  + FileToEdit + Chr(34),"") 
   RunProgram("/Applications/KompoZer.app ", Chr(34)  + FileToEdit + Chr(34),"") 
Trying to launch Kompozer with arguments. Tried both neither work.

Without arguments runs perfectly.

If I use terminal with this line

open /Applications/KompoZer.app --args "Main Form.html"

Kompozer runs and opens the file to edit.

I am missing something again I think.


PS

Just Tried

Code: Select all

RunProgram("Open", "/Applications/KompoZer.app --args " + Chr(34) + FileToEdit + Chr(34),"")
And it worked! Just looked at Open and passed the whole line to run composer as an argument to open.

Slowly getting the hang of it.

Regards

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: RunProgram() Again!

Post by deseven »

Just to explain why it works that way.

App bundles (*.app) are just an abstract layer built on top of a simple unix way to execute binaries. They are basically just folders and nothing more.
Since PB's RunProgram doesn't know anything about that abstract layer, you have to use open -a OR run the executable directly.

For example:

Code: Select all

RunProgram("/Applications/KompoZer.app/Contents/MacOS/KompoZer", ~"\""  + FileToEdit + ~"\"","") ; need to check if your main executable is called like that
RunProgram("open", ~"-a /Applications/KompoZer.app \"" + FileToEdit + ~"\"","") ; passes your argument through cocoa api
RunProgram("open", ~"-a /Applications/KompoZer.app --args \"" + FileToEdit + ~"\"","") ; passes your argument in a typical unix way (equivalent of the first method)
You can also read man open for advanced usage. For example you can omit full path to app at all (open -a KompoZer.app) or, even better, run app by its bundle indentifier (open -b com.example.kompozer)
Post Reply