Tuesday, December 6, 2022


MacScripeter.net will transition to a new Discourse server soon. Watch this space for the date and time of the transition. Please expect the site to experience periods of outage during this transition. See this and this for more details.

#1 2021-06-12 09:07:57 am

Registered: 2019-10-23
Posts: 1092

Conclusion of a error with use statement

Most people who do ASObjC knows they need to have a use statment to find the target framework.

I was making a script that use WebKit and run this in the Script Editor, everything worked fine.
When I later save it to applet it didn't work (it has nothing to do with main thread).
On the other hand I force Script Editor to use Run in Foreground also worked.

Next step... was to try the template of cocoa-applescript-applet.app and this time I got a error
message. From that conclusion I saw that I had missed the use statement for framework webkit.
So I add this and save the script as applet and everything was working.

What I like to share with this post is AppleScript could be running in so many ways and becouse its looks like working in one environment doesn't mean it will work in other. And this time it has nothing to do with running in main thread or not.

If I remember correct Shane said something about use statment use the scripting bridge to find methods. It looks like Script Editor is not so picky about that but applet are.

Node-RED makes it easy to automate IoT



#2 2021-06-12 10:45:31 am

From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1522

Re: Conclusion of a error with use statement

Fredrik71. Thanks for the post.

The situation is even more insidious than one might think. Shane does a great job of explaining this in his book, and I think the third paragraph requires special note.

MOST of the time you will probably be using methods only from Foundation, or perhaps AppKit. And you may have accidentally left off the use framework statements, and found your code still works. It is important you do not do this, though, because you are asking for intermittent problems. Here’s why.

When you include a use framework statement, the application using the library loads the framework. A framework can only be loaded once, and cannot be unloaded, and nearly every application will already have loaded Foundation and AppKit themselves. So if your library uses only them, you might be fine.

But a use framework statement does something extra that a normal application does not: it also loads a special framework .bridgesupport file. This is an XML file that contains extra information on the enums, constants, functions and methods in the framework, and tells the scripting bridge how to deal with them.

2018 Mac mini - macOS Monterey - Script Debugger 8



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)