Page 1 of 1
Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Mon Mar 20, 2017 6:39 pm
by PB2004
Brand new to Mac OS, and trying to port an existing PB program to it. Having syntactical trouble getting TextEdit.app to just open my pre-generated text file and sit there so the user can look at it and maybe close it it he wants to and continue on with the PB app.
In my PC version the code
Code: Select all
RunProgram("notepad.exe", path$ + "\" + filename$,"C:\WINDOWS\system32")
worked fine.
I've spent an embarrassing amount of time searching and trying get Mac OS equivalent behavior without success. Is someone could post a workable line, I'd really appreciate it. Thank you.
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Mon Mar 20, 2017 7:22 pm
by PB2004
While we are at it, I need to do the same thing with a .pdf file. Both .txt and .pdfs preview easily in Finder. Hopefully this is also a runprogram solution?
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Mon Mar 20, 2017 8:10 pm
by PB2004
I guess the "Simple PDF Viewer" topic begs to differ.
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Mon Mar 20, 2017 8:32 pm
by said
Hi,
You can try this (it used to work fine for me, been a while since i have not used Mac), once the file is given the adequate extension:
Code: Select all
curDir = GetCurrentDirectory()
SetCurrentDirectory("/")
RunProgram("open", Chr(34) + fileName + Chr(34),"")
SetCurrentDirectory(curDir)
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Mon Mar 20, 2017 9:09 pm
by PB2004
Thanks said but changing the directory seems needless and does not work.
I've come close with RunProgram("open",GetCurrentDirectory() + filename$,"") PROVIDED filename$ has no spaces in the name.
Thought I saw some kind of escaping about 200 screens back. Any suggestions would be appreciated.
The same is true if the target is a .pdf. Works great if no spaces in the name. How can I beat the space in the name problem?
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Mon Mar 20, 2017 9:52 pm
by Shardik
The following command opens a text file in TextEdit (you have to substitute
/PathToTextFile/TextFile with an actual path and text file name; the #DQUOTE constants allow you to use spaces in your folder names or file names; #DQUOTE$ displays a double quote character as also Chr(34) does):
Code: Select all
RunProgram("Open", "/Applications/TextEdit.app " + #DQUOTE$ + "/PathToTextFile/TextFile" + #DQUOTE$, "")
To open a PDF file with your default PDF viewer (in my case Abobe Reader):
Code: Select all
RunProgram("Open", #DQUOTE$ + "/PathToPDFFile/PDFFile" + #DQUOTE$, "")
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Tue Mar 21, 2017 1:17 am
by PB2004
That did the trick. In retrospect, Said was right about the Chr(34). You guys are awesome!
So for any noobs that come along, my working variant is:
Code: Select all
RunProgram("open", Chr(34) + GetCurrentDirectory() + "my file.txt" + Chr(34),"")
The noob is curious though - this "open" syntax does not seem to conform to the F1 parameters for the RunProgram() command (filename$, Parameter$, WorkingDirectory$, Flags). So what is going on here?
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Tue Mar 21, 2017 1:47 am
by citystate
I've got zero experience with MacOS, but I'd imagine that "open" is a system command that behaves like an executable file...
Re: Mac OS Equivalence for RunProgram("Notepad.exe .....
Posted: Tue Mar 21, 2017 10:17 pm
by Shardik
PB2004 wrote:The noob is curious though - this "open" syntax does not seem to conform to the F1 parameters for the RunProgram() command (filename$, Parameter$, WorkingDirectory$, Flags). So what is going on here?
citystate wrote:I've got zero experience with MacOS, but I'd imagine that "open" is a system command that behaves like an executable file...
citystate's imagination is correct:
open is a BSD system command located in /usr/bin.
You may take a look into
Apple's documentation for this command or simply open a terminal and type