Use LNS freeware scripting additions on Catalina and Mojave

LNSOSAX

LNSOSAX provides access to the LNS scripting additions on macOS Catalina and Mojave systems.

As described in the Mojave Brings In Big Security Changes blog post (see the Farewell Scripting Additions section), AppleScript scripting additions (OSAXen) are no longer supported in macOS Mojave. This presents a serious problem for older scripts which use the LNS scripting additions.

Installation

  1. Download and mount the LNSOSAX disk image
  2. Copy the LNSOSAX application to your Applications folder.
  3. Make sure that you launch the LNSOSAX application once manually. macOS will ask for permission to run the application because it was downloaded from the internet.

Usage

The LNSOSAX app makes it possible to continue using the LNS scripting additions with minimal changes to your scripts. Once LNSOSAX is installed, you only need to add these lines to the beginning of your script:

use scripting additions 
use application "LNSOSAX"

That’s it. Now the LNSOSAX application is used to handle all the LNS scripting addition commands for your script. Please note that this will be slower than before, but your script will run.

Here’s a full example using the LNSOSAX AEPrint of command:

use scripting additions
use application "LNSOSAX"

AEPrint of "Hello Again!"

LNSOSAX includes the following scripting additions:

  • List & Record Tools.oxax
  • property List Tools.osax
  • XMLTools.osax

Backwards Compatibility

LNSOSAX can be used on macOS 10.12 (Sierra) and above. When using LNSOSAX on pre-Mojave systems, I suggest removing the LNS scripting additions from your system to avoid conflicts.

WARNING

You should find alternative means of accomplishing what the LNS scripting additions did for you in the past. The Script Debugger support forum provides a list of AppleScript libraries you can use. And then there is AppleScript Objective-C which gives you access to all the feature of Apple’s Foundation framework (and other Objective-C frameworks).

Support

If you have questions concerning LNSOSAX please post them on the Script Debugger Support Forum or MacScripter.net. Bugs can be filed as issues with the GitHub repository.

License

LNSOSAX is licensed under the MIT license (see the LICENSE file for details).

Source Code

Source code for LNSOSAX is available on GitHub. Pull requests are welcome.

See Also

SatimageOSAX

2 Likes

Hi, Mark!
According to my first tests, parsing and generating a large XML is very quick! At least as quick as using XML Tools.osax the old way.

But there is also a problem. It’s not possible to write the generated xml to a file:

set destXmlFile to ( do shell script “echo ~/Desktop/Output.xml”)
generate XML XmlRec saving as destXmlFile with generating UTF8
–> error number -50

Without file output it works:

generate XML XmlRec with generating UTF8

The generate XML command expects a AppleScript file or alias object. Passing a path string won’t work. The solution is simple:

generate XML theResult saving as POSIX file destXmlFile with generating UTF8

Here is my full test script:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use application "LNSOSAX"

set theXML to "<start>
	some text
	<tag attribute1=\"value1\" attribute2=\"value2\"/> 
	some more text
	<tag attribute1=\"value3\" attribute2=\"value4\"/>
</start>"

set theResult to parse XML theXML with including empty elements
set destXmlFile to (do shell script "echo ~/Desktop/Output.xml")
generate XML theResult saving as POSIX file destXmlFile with generating UTF8
1 Like

Actually it did work with a POSIX path string with the regular osax.
Therefore I didn’t even try with a file or alias object. But then I know. Thanks!

Mark, many thanks for providing this very useful tool.

I’d like to give back, or maybe give forward, a little, so I’ve cleaned up the text at https://latenightsw.com/support/freeware/list-record-tools/, and have it available below as an example script:

LNSOSAX List & Record Commands Examples

Mostly the text from the above reference, but any errors are mine.

(*
REF:  https://latenightsw.com/support/freeware/list-record-tools/
*)

use scripting additions
use application "LNSOSAX"

(*
The following are some brief examples illustrating how the List & Record Tools in the LNSOSAX.app that can be used.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Record Processing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

One of AppleScript’s major limitations is that it cannot dynamically access items in records 
    – record keys must be known at compile time. 
    
The List & Record Tools commands provides a series of commands for accessing records in a dynamic fashion.

AppleScript records can contain properties and user properties. 

    A property is defined by an application through 
    its dictionary and is represented internally via a 4-character code. 
  
    For example, name is a term defined by AppleScript and many applications. 
    The code {name:"Mark"} creates a record containing a property with the 4-character code ‘pnam’ 
    and the value "Mark". 
    
    A user property is defined within AppleScript.
    
    The term myAge is not defined in any dictionary and creates a user property when used in a record: 
    (e.g. {myAge:42}).
  
  NOTE: On Mac OS X systems prior to 10.6, AppleScript converts user property names to lower case, unless the |Name| notation is used. Because of this, user property names must be given in lowercase on pre-10.6 systems.

Accessing Properties

4 commands are provided for working with properties:
  get, set, or delete properties in a record, 
  get the 4-character IDs of all the properties in a record:
*)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
get property "pnam" in {name:"Mark"}
--> "Mark"
set property "pnam" in {name:"Mark"} to "Gerry"
--> {name:"Gerry"}
delete property "pnam" in {name:"Mark"}
--> {} 
get property IDs {name:"Mark"}
--> {"pnam"} 
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(*
Accessing User Properties

4 commands are provided for working with user properties:
  get, set, or delete user properties in a record, and
  get the names of all the user properties in a record.
*)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
get user property "myAge" in {myAge:42}
--> 42
set user property "myAge" in {myAge:42} to 28
--> {myAge:28}
delete user property "myAge" in {myAge:42}
--> {} 
get user property names {myAge:42}
--> {"myAge"} 
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
List Processing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The List & Record Tools scripting addition provides three commands for treating AppleScript lists as sets. These commands were originally part of the now discontinued LNS Scripting Additions. We have received frequent requests to provide them for Mac OS X.

Set Intersection (return all items that are common to two lists)
Here’s an example involving integers where the command returns only those integer values common to both lists:
*)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
intersection of {1, 2, 3} and {2, 3, 4}
-->{2, 3} 
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(*
This command can handle other data types such as strings, dates, etc. For strings, it honours AppleScript’s considering case, whitespace, hyphenation.

Set Difference (return items that are not common to two lists)
Here’s an example involving integers where the command returns only those values that are not common to both lists:
*)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
difference of {1, 2, 3} and {2, 3, 4}
-->{1, 4} 
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(*
This command can handle other data types such as strings, dates, etc. For strings, it honours AppleScript’s considering case, whitespace, hyphenation.

Set Union (return all unique items from both lists)
Here’s a simple example involving numbers where the command returns unique values from both lists:
*)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
union of {1, 2, 3} and {2, 3, 4}
-->{1, 2, 3, 4} 
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(*
Here’s another example involving numbers, booleans, and strings:
*)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
union of {1, 2, true, "Hello", 3, 4} and {false, 2, "Hello", "Mark", 10}
-->{ "Hello", "Mark", false, 1, 2, 3, 4, 10, true } 
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(*
Like the intersection and difference commands, this command honours AppleScript’s considering case, whitespace, hyphenation.
*)

Hi Mark.

So here’s a possible alternative means…? I’m wondering… who wrote those three scripting additions? How hard would it be to convert/port them to standard AppleScript Libraries now?

I see they’re no longer maintained, but I imagine they wouldn’t be too hard for any decent AS dev to adapt the source code into standard AppleScript Libraries. I’d possibly be willing to do it myself and make the result available to everyone of course.

I’ve looked in the packages for each of them and there’s no way to see the source code that I’m aware of (it’s stored in .rsrc files) and seems to be read only.

Is the source code at all possibly available to someone willing to try to do this conversion/port? And/or might there be anyone else willing to help convert them? If this could be done it would obviously solve the above problem.

Thoughts?
Thanks!!

1 Like

For reasons of my own I’m not interested in releasing the LNS Additions source code openly. Additionally, preparing source code for open source release its its own task that I don’t have the time for at present.

My fears that Apple might remove the mechanism used to repackage the scripting additions as an application were not founded. I can probably remove the stern warning you quoted.

I imagine that the Intel compatibility facility within Apple Silicon macs will remain for the foreseeable future. As such, you should be okay (apart from some performance differences) to continue using the LNSOSAX and SatimageOSAX applications.

1 Like

It’s probably also worth mentioning that AppleScriptObjC can now handle many of these functions without the need for external code.

Hi Mark. Didn’t see this reply till now for some reason. Thanks for the explanation. It would still be great if they could be converted to standard libraries. Understood if you don’t want to release it publicly for someone else to do that. I’m guessing it’s not exactly a priority for you to do it yourself, or you’d have suggested that, right? :wink: I don’t suppose there’s anyone else you know and trust who might do it? I might even be willing to pay for that, to a point.

(Though, noted, Shane’s comment which I’ll reply to in a moment, which may make this all moot? I don’t know enough about how ASObjC works to be confident using that.)

Interesting point Shane, though as mentioned in my reply to Mark just now, I have never quite been able to figure out how to use that side of AS.

Is this a significant enough point such that it makes these osaxen redundant or something?

It’s possible I’m not even asking the right question(s) here.

It makes much of what they do redundant.