Page 1 of 1

RunProgram() Again!

Posted: Fri Dec 13, 2019 9:07 am
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???

Re: RunProgram() Again!

Posted: Fri Dec 13, 2019 12:10 pm
by Wolfram
Are you sure your program is in "/Users/YOURNAME/Applications" ?
Normally the programs are in "/Applications".

Re: RunProgram() Again!

Posted: Fri Dec 13, 2019 12:50 pm
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

Re: RunProgram() Again!

Posted: Sun Jan 19, 2020 10:06 am
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

Re: RunProgram() Again!

Posted: Fri Jan 31, 2020 3:44 pm
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)