Crash when using AS Studio with doc-based Cocoa app
Crash when using AS Studio with doc-based Cocoa app
- Subject: Crash when using AS Studio with doc-based Cocoa app
- From: Matt Gemmell <email@hidden>
- Date: Sun, 12 May 2002 14:43:50 +0100
Hi all,
I have a standard Cocoa document-based application (not created with any
of the AS Studio templates). I found that I needed to execute an
AppleScript for a certain piece of functionality (I need to ask BBEdit
for the value of a couple of its preferences), so I decided to use AS
Studio. This is my first time ever using AS Studio (I've been a
Cocoa/Obj-C developer for more than a year).
I have a button in my document window's UI which triggers the
AppleScript function. I selected the button in IB, checked the
Action/onclick handler, and made a new script in my PB project. I wrote
my AppleScript code. I linked my project against the AppleScriptKit
framework, and added an AppleScript build phase. Then I ran the project.
I found that I had a crash when creating a new document, but only if
there were no other documents open at the time. I went back into IB,
selected the document window, and in the AppleScript pane of the
inspector I checked the script I was using for the button's onclick
handler. That seemed to solve that problem. I admit to having no idea
why, but didn't want to look a gift horse in the mouth. I can now open
and close as many documents as I like without incident. But, there's
still a problem (I'm not typing all this for my health!)
The first time I execute my script (code below), it works fine. It even
works fine if I execute it multiple times in the same document window.
But, a crash (SIGSEGV usually, but occasionally SIGBUS or even SIGABRT -
that's a new one for me!) occurs if I have several doc windows open and
I execute the script when it has been previously executed at least once.
This description is fuzzy because I can't quite pin down the
circumstances. The prerequisites for the crash seem to be:
- Script has run before at least once
- At least one document window has been closed (probably one in which
the script was previously run)
Any thoughts? I'm really not au fait with how AS Studio works, or how it
loads AppleScripts (whether it uses a single instance of the script for
the whole app, or loads a new instance for each document, or whatever),
and I'm hoping that someone here may have some inkling of what's going
on. I'm a bit at sea with this. I'm suspicious about the fact that it
seems to happen only if I've closed a document window; makes me wonder
if something isn't being released somewhere. Thanks in advance for any
thoughts.
Meantime, my script's code is below. The 'on clicked' handler is the
only code in the script file, and this script is the only one in the
app.
on clicked theObject
-- Get values from BBEdit
tell application "BBEdit 6.5"
set htmlPrefs to (get html preferences)
set rootDirectory to (root directory of htmlPrefs) as string
set defaultFileName to default file name of htmlPrefs
end tell
-- error checking to be inserted here... :)
-- Change path-delimiting colons to slashes
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set itemCount to count of every text item of rootDirectory
set textList to {}
-- Get rid of first text item (drive name) for root-relative path
repeat with i from 2 to itemCount
set textList to textList & text item i of rootDirectory
end repeat
set AppleScript's text item delimiters to "/"
set rootDirectory to "/" & textList as string
set AppleScript's text item delimiters to oldDelims
-- Put values into UI
set contents of text field 2 of box 1 of window 1 to defaultFileName
set contents of text field 4 of box 1 of window 1 to rootDirectory
end clicked
Best,
-Matt
--
Matt Gemmell
Scotland Software
<
http://www.scotlandsoftware.com/>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.