Closed 67740307-cbe9-4893-960c-a5f7636ec213 closed 22 years ago
I have the following AppleScript which I have also converted to Python:
tell application "CodeWarrior IDE" activate open file file1 disassemble file file2 set xText to (get text of document 1) end tell
I had some difficulty converting the last command into Python, but the below should work (or so I have been told):
import CodeWarrior, time
cw = CodeWarrior.CodeWarrior(start=1)
time.sleep(5)
cw.activate()
cw.open(file1)
cw.disassemble_file(file2)
time.sleep(5)
xtext = app('CodeWarrior IDE').document[1].text
However, instead of the text that I expect, xtext is equal to 'app('CodeWarrior IDE').document[1].text.all'
Bill Fancher looked at CodeWarrior and said that it is returning cText which is not being handled by Python.
Logged In: YES user_id=572605
I made a typo: xtext = app('CodeWarrior IDE').document[1].text should be: xtext = cw.get(CodeWarrior.text(CodeWarrior.document(1)))
Logged In: YES user_id=45365
Robin, you have to give a more complete example. I can get neither the applescript nor the Python program to work. I've filled in valid filenames for file1 and file2, but the Applescript keeps giving the error "CodeWarrior IDE 4.2.5 got an error: Bad name for file. some object".
Could you maybe create a sample soucre file (plus project?) and the real AppleScript you used, and pack it all up?
Logged In: YES user_id=572605
I will create a project and attach it, however, you cannot use CodeWarrior IDE 4.2.5 because there is are bugs in it that have to do with AppleEvents. You have to use v 5.0 of the IDE.
Logged In: YES user_id=572605
Here is a project, applescript and python script. You will have to
change the paths in the script to wherever you place the project.
Also, there is a bug in the last line of the python script because I
can't remember the exact syntax I had to use to capture the text
from CodeWarrior. Maybe you will have better luck than me.
Logged In: YES user_id=572605
Oops! I forgot to check the stupid (and unneccessary) checkbox.
Logged In: YES user_id=572605
I left out the python script. I will upload a new file
Logged In: YES user_id=45365
I removed the "disassemble file" bit and did that manually (it indeed doesn't work in CW7) and ran the Python script under the debugger.
The strange thing is that the reply AppleEvent indeed does not have a "----" item (this is the return value), so cw.get() is "right" in returning None. (Note that the problem sketched by Bill Fancher, missing support for cText, would have shown up differently: you would have gotten an aetypes.Unknown('ctxt', data) object back).
If you want to see this for yourself run the script under the debugger. The last line, by the way, should be "text = cw.get(CodeWarrior.text(CodeWarrior.document(1)))"
After the aesend() call in cw.get() you'll see there's no ---- argument.
I vaguely remember about there being a second protocol for send replies to AppleEvents (maybe especially for big replies?) but a quick look through the documentation hasn't revealed anything. I'll ask on the SIG whether anyone has any ideas.
Logged In: YES user_id=45365
As Bill Fancher explained this turns out to be an ideosyncracy in CodeWarrior (and possibly other TextEdit-related programs). The text of the window is actually multiple text runs. In this case there's only one, so the correct lines in Python to grab the text of the window is txt = cw.get(CodeWarrior.editor_document(1).text(1))
AppleScript apparently has a workaround for this situation, but I think that for now I'll flag this as "won't fix".
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = 'https://github.com/jackjansen' closed_at =
created_at =
labels = ['OS-mac']
title = 'Python not handling cText'
updated_at =
user = 'https://bugs.python.org/robinsiebler'
```
bugs.python.org fields:
```python
activity =
actor = 'jackjansen'
assignee = 'jackjansen'
closed = True
closed_date = None
closer = None
components = ['macOS']
creation =
creator = 'robinsiebler'
dependencies = []
files = ['597']
hgrepos = []
issue_num = 598981
keywords = []
message_count = 9.0
messages = ['12104', '12105', '12106', '12107', '12108', '12109', '12110', '12111', '12112']
nosy_count = 2.0
nosy_names = ['jackjansen', 'robinsiebler']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue598981'
versions = []
```