Use LNS freeware scripting additions on Mojave

mojave

(Mark Alldritt) #1

LNSOSAX

LNSOSAX provides access to the LNS scripting additions on macOS 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

I STRONGLY encourage you not to rely on LNSOSAX as a long term solution.

I suspect Apple will remove the functionality on which LNSOSAX depends in future versions of macOS. 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


Codesigned XML Tools?
(Jörgen Stahle) #3

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


(Mark Alldritt) #5

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

(Jörgen Stahle) #6

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!


(Jim Underwood) #7

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.
*)

Documentation Links