Naylin opened this issue on Feb 01, 2007 · 12 posts
Naylin posted Thu, 01 February 2007 at 3:41 AM
Using Windows, I can use: os.startfile(PathToFile) to open a file in it's default application. Does anyone know or can anyone test if this also works on a Mac???
If it doesn't work, does anyone know how I can accomplish the same on a Mac?
Thanks in advance,
--Naylin
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
My
Store My
Gallery
____
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
"You have the right to remain silent. Anything you say can and
will be misquoted and then used against you."
adp001 posted Thu, 01 February 2007 at 1:44 PM
This is Windows only (see the Python documentation at http://www.python.org).
Other systems may not allow something like this (for security reasons).
If you know whitch program should handle your datafile, perhaps you can use a system call to exec the application.
If you want to show something that a webbrowser can handle, look into the Python docu. There is a "webbrowser" module that runs on any OS where Python is available.
PhilC posted Sat, 03 February 2007 at 1:54 AM
poser.ExecFile('filepath') works on PC and Mac for Poser 5 & 6 and PC Poser 7
Could someone please test with Poser 7 on a Mac. My tests appear to show that it does not.
###########################
pathname = os.path.split(poser.AppLocation())[0]
filePath = os.path.join(pathname, 'Runtime', 'Python', 'poserScripts', 'test', 'execfile_1.py')
poser.ExecFile(filePath)
##########################
print "execfile_1.py run OK"
#########################
Run ExecFileTest.py to execute execfile_1.py
Works on a PC fails on a Mac
adp001 posted Sat, 03 February 2007 at 5:08 PM
Hm. No need to assemble a filename for poser.ExecFile().
poser.ExecFile("Runtime:Python:poserScripts:<script.py>") works fine for windows (and should for Macs, too).
If poser.ExecFile() won't work on Macs with P7, try Pythons execfile() insteed.
PhilC posted Mon, 05 February 2007 at 7:51 AM
Thanks, execfile() works on Poser 7 Mac. I'd forgotten that it was the same word just lower case.
Incidentally am I right that the Mac path delimiter has changed to "/"
Again thanks.
adp001 posted Mon, 05 February 2007 at 8:14 AM
As you may know you can find out the seperator actually used by the OS with
os.sep
os.pathsep
sep The character used by the operating system to separate pathname components, for example, "/" for POSIX or ":" for Mac OS 9. Note that knowing this is not sufficient to be able to parse or concatenate pathnames -- use os.path.split() and os.path.join() -- but it is occasionally useful. Also available via os.path.
pathsep The character conventionally used by the operating system to separate search path components (as in PATH), such as ":" for POSIX or ";" for Windows. Also available via os.path.
semidieu posted Mon, 05 February 2007 at 8:16 AM
Great info !
But does it work for all kind of file, or only Python files ? For example, I wanted to open a text file in the default editor. Will this work with ExecFile (and execfile for Mac) ?
adp001 posted Mon, 05 February 2007 at 9:33 AM
poser.ExecFile() and execfile() both are to start Python scripts only.
If you need to start any other executable from within Python, you probably may want to use os.popen(). But better read the docu :)
popen( command[, mode[, bufsize]]) Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r'
(default) or 'w'
. The bufsize argument has the same meaning as the corresponding argument to the built-in open() function. The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None
is returned. Availability: Macintosh, Unix, Windows.
Changed in version 2.0: This function worked unreliably under Windows in earlier versions of Python. This was due to the use of the _popen() function from the libraries provided with Windows. Newer versions of Python do not use the broken implementation from the Windows libraries.
adp001 posted Mon, 05 February 2007 at 9:43 AM
@**semidieu:
** Mayby you are interested to know that python has some special Macintosh libs. Search the online docu for Macintosh. :
Save as'' versus
Save as Applet''semidieu posted Tue, 06 February 2007 at 6:42 AM
Thanks... I was hoping it could be easier...
I already tried "popen", but it seems to not work exactly the same on PC or Mac. For example:
os.popen('notepad.exe text.txt')
work for PC. But for Mac, someone told me to use:
os.popen('open text.txt').
This doesn't work on PC... and I can't test on a Mac to check if it's working...
adp001 posted Tue, 06 February 2007 at 7:05 AM
import sys
if sys.platform.startswith("win") :
ex = "notepad.exe"
else:
ex = "open"
os.popen("%s text.txt" % ex)
But, sorry, why would you do that? Any user should be able to start his prefered texteditor without any help.
What about getting the text you need with a dialog and store it where it belongs to?
semidieu posted Tue, 06 February 2007 at 8:17 AM
I'm working on a GUI interface to apply the Art Materials shader by Olivier. I want to "disable" the AO feature when the material correspond to a list of name in a text file. This text file must be editable, so everyone can make their own "list" (add, remove, edit).
And... yes, you could simply browse the folder and double-click the file to open... But I would like it to be accessible directly from my GUI.