MacPython applet problem

B

boris m

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
 
R

Ronald Oussoren

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
 
B

boris m

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top