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.