A better way to develop ASObj-C

foundation
asobjc

#1

One of the problems with developing ASObj-C scripts is an error in the script can some times cause the script editor to crash in Script Debugger, Script Editor, … This is because the script runs inside the application process.

The better way to work with ASObj-C scripts is to use two editors. I came up with a simple way to use two editors. The idea is to do all the editing and development in SD and only run the script in Script Editor.

I did this manually (using copy and paste then running) for for a while and it was distracting and tedious with rapid “edit script and try again” efforts. So I created a script that will automatically get the text in the front window of SD then switch to Script Editor, open a new window containing the text from Script Debugger, then compile and run the script. This does not involve using the clipboard. I call the script using FastScripts but other ways can be used to call it. Converting the script to an applet and double clicking it in Finder would work but might prove tedious if used often.

On my Mac this works with no noticeable delay. Older Macs, or Mac running a lot of apps, might take a tiny bit of time but this allows the development to go forward without the distraction. When used with a keyboard short cut it is fast and easy. A single keypress runs the script in another application. Then you make corrections in SD and another single key press runs it in another application.

The only real difference between this and just running everything in Script Debugger is you won’t have to relaunch SD a lot. Of course this process does not allow stepping through a script with ASObj-C with the debugger, but trying to step thought an ASObj-C script can cause problems such as SD does not crash and keeps running, but doesn’t work correctly. Then you end up chasing phantom bugs a lot. When woking with AppKit SD often crashes if trying to step though it.

The script is listed below. I also included a zipped version of the script called “00) Run fornt window in Script Editor.scptd.zip”

tell application "Script Debugger"
	activate
	set SDSourceText to source text of document 1
end tell

tell application "Script Editor"
	activate
	set TheDocument to make new document
	set text of TheDocument to SDSourceText
	delay 0.5
	compile TheDocument
	execute TheDocument
end tell

Bill Kopp

00) Run fornt window in Script Editor.scptd.zip (6.8 KB)


Update to better way to develop ASObj-C