The fact that property values cannot be not preserved between two times a code signed applet is run is obvious and easy to adapt to. But recently I have noticed a bigger problem: there is also a difference in scope for properties in scripts compiled with Script debugger versus Script Editor. And these differences are present even for non signed scripts.
I guess this is well known for you guys, and maybe it is a deliberate feature of SD, but I then would need som help – because it have made at least one applet with complicated code, made for server use, unusable with Mojave where code signing is in practice necessary. I’m quite sure it will break other applets of mine too.
I’m not sure what the exact scope limitations are for properties with SD, but the example script below demonstrates at least one of them: properties that are defined by the run handler are (under some circumstances?) not preserved for the idle handler – if compiled under Script Debugger.
I haven’t even noticed these differences until beginning to code sign my applets for server use: An applet that is edited in SD, but not being code signed, behaves as I expect them when start it from Finder. But when code signed with SD, the applet breaks.
If I run the same applet inside SD in idle mode it also breaks – even if the applet is NOT code signed. On the other hand, if the applet is exported and code signed from Script Editor (if it has included script libraries I have to move them from inside the bundle to my user library) – the script does NOT break.
So my conclusions are:
• There is an essential difference between SE and SD in how handle property values are handled. Specifically properties that are defined by the run handler and used by the idle handler.
• Non signed applets created with SD are somehow recompiled by MacOS to use the ”original” Applescript behavior. But when code signed, the applet preserves its ”SD-behaviour” in respect to differences concerning preservation of property values.
I my real case I have a complicated applet for server use, where the code is by far too large to store in one script. Therefore big parts of it is moved to script libraries, included in the application bundle, to be called from the main script. This have worked fine in production for years. But now I need to code sign this applet for use on a server with Mojave – and then it breaks.
At startup the main script stores the script libraries as properties. Then, at start in the run handler, redefines some of the script-library-properties’ own properties. In some cases those properties-in-script-library-properties are also redefined from time to time in the idle handler.
Below is a simplified example illustrate the principle. To reproduce the problem run it as a standalone applet and then from inside SD in idle mode. Or Code signe the applet fråm SD.
What I hope with this post:
• A description of how the handling of properties differs when compiled in SD compared tu usual Applecsript behavior (if these differences ar delibarate and if there is more to know besides my conclusions above)
• Some advice on alternative methods… if this is the way it is meant to be
Here is the code example. The same code example is also attached as a application bundle.
PropScopeDemo.zip (63.6 KB)
Main.scpt:
property L1 : script “Lib1”
property L2 : script “Lib2”
on run
set L1’s ySomeProperty to “~/Library/Logs/ThisApp/”
set L1’s ySomeOtherProperty to ( current date )
set L2’s L1 to L1 – passing the log functions stored in L1 to L2 (which also have a property named L1)
L1’s aHandler() – Works with SD
L2’s anotherHandler() – Works with SD
end run
on idle
set L1’s ySomeOtherProperty to ( current date ) – a property that is redefined every now and then
L1’s aHandler() – Partly fails with SD
L2’s anotherHandler() – Totally fails with SD
return 1
end idle
Lib1.scpt:
property ySomeProperty : missing value
property ySomeOtherProperty : missing value
on aHandler()
activate
set dateString to “” & ySomeOtherProperty
display alert ySomeProperty message dateString buttons {“Cancel”, “OK”} cancel button 1
end aHandler
Lib2.scpt:
property L1 : missing value
on anotherHandler()
L1’s aHandler()
end anotherHandler