Mac OS Equivalence for RunProgram("Notepad.exe .....

Just starting out? Need help? Post your questions and find answers here.
PB2004
User
User
Posts: 33
Joined: Sat Aug 11, 2007 6:16 pm
Location: Frisco, US

Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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.
PB2004
User
User
Posts: 33
Joined: Sat Aug 11, 2007 6:16 pm
Location: Frisco, US

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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?
PB2004
User
User
Posts: 33
Joined: Sat Aug 11, 2007 6:16 pm
Location: Frisco, US

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post by PB2004 »

I guess the "Simple PDF Viewer" topic begs to differ.
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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)
PB2004
User
User
Posts: 33
Joined: Sat Aug 11, 2007 6:16 pm
Location: Frisco, US

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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?
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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$, "")
PB2004
User
User
Posts: 33
Joined: Sat Aug 11, 2007 6:16 pm
Location: Frisco, US

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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?
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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...
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Mac OS Equivalence for RunProgram("Notepad.exe .....

Post 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

Code: Select all

man open
Post Reply