By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,271 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,271 IT Pros & Developers. It's quick & easy.

MacPython applet problem

P: n/a
I am running Python 2.3 on Mac OS 10.3.

My problem is that applets don't seem to work. If I run a python
script in the terminal, everything is fine. If I run the same script
as an applet, nothing happens. The applet starts up, but dies after a
second or two.

I used applets quite frequently unter OS9 and never had a problem with
them. Has anyone any idea why applets on OS X don't work the way they
did in OS 9?

Thanks in advance,
Boris
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

On 10-mei-04, at 12:02, boris m wrote:
I am running Python 2.3 on Mac OS 10.3.

My problem is that applets don't seem to work. If I run a python
script in the terminal, everything is fine. If I run the same script
as an applet, nothing happens. The applet starts up, but dies after a
second or two.

I used applets quite frequently unter OS9 and never had a problem with
them. Has anyone any idea why applets on OS X don't work the way they
did in OS 9?


There's probably a traceback or other message in the console log
(Console.app). That should point you in the right direction.

Ronald
Jul 18 '05 #2

P: n/a
After some tinkering with AppleScript, I found a workaround for my
problem. I think it is worth sharing, so here we go...

As Ronald pointed out, python applets currently do not support
input/output functions like 'input' or 'print'. Of course, I could run
the script from the command line, but then I would not have a nice
drag and drop feature.

I wanted to have both drag/drop (via sys.argv) *and* input/output
functions. So I wrote an AppleScript droplet that allows me to do
this. The droplet is currently limited to accept just one item, but it
could easily be extended.

This was one of my first explorations into AppleScript, so I am more
than open to suggestions and improvements.

Boris

---

--> save as application
on open dropItem
set itemPath to POSIX path of dropItem
set itemPathStr to (itemPath) as string
set itemPathCLI to textReplace(itemPathStr, " ", "\\ ")

tell application "Finder"
set currentMacFolder to (container of (path to me)) as alias
set currentFolder to POSIX path of currentMacFolder
set folderPath to (currentFolder) as string
end tell

set folderPathCLI to textReplace(folderPath, " ", "\\ ")
--> don't forget chmod +x myscript.py
--> myscript.py is in the same directory as the droplet
set scriptPath to folderPathCLI & "myscript.py" & " " & itemPathCLI

activate application "Terminal"
tell application "Terminal"
do script scriptPath
end tell
end open

on textReplace(theText, srchStrng, replStrng)
tell (a reference to AppleScript's text item delimiters)
set {od, contents} to {contents, {srchStrng}}
try
set {textList, contents} to {(text items of theText), {replStrng}}
set {newText, contents} to {(textList as text), od}
return item 1 of result
on error errMsg number errNbr
set contents to od
error errMsg number errNbr
end try
end tell
end textReplace

My problem is that I the script needs some user input (I want to drag some
text files to the applet and then specify some changes). For the user input
I am using:

inputStr = raw_input("Enter a number: \n>>> ")

This, however, seems to produce the error.


That's right. I'm pretty sure applets on OSX do no (yet) support user
input/output using the input function and print statement.

IIRC this is on the TODO list for the next release of MacPython.

B.T.W. with MacPython the default action for .py file is to execute
them in a Terminal window, which gives you complete support for input
and print.

Ronald

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.