Hi,
I have just started experimenting with Javascript and would appreciate a check of my understanding.
-
Applescript is not being developed and as it does not run on finger painting devices (iOS) it is likely that it will be removed from MacOS at some point in the future.
-
Applescript communicates with applications using Apple Events which are or are part of what is known as Open System Architecture or OSA.
-
Apple now favour scripting using Javascript for Applications which is known as JXA. It was launched circa 2014 and described is as a peer to Applescript.
-
JXA should not be confused with JSX which is something to do with XML.
-
JXA communicates with non-Omni applications using Apple Events and OSA.
-
Omni have developed their own javascript interpreter which is built into all their applications i.e. iOS apps as well.
-
Is it correct to describe the Omni javascript as JXA. It appears to me that the OmniOutline dictionary displayed in Apple Script Editor is different to the commands described in the Omni-Automation tutorial e.g. I see Row but not item and no sign of Editors or Root. Should or does the Omni version have a different name e.g. Javascript for OmniAutomation JOA perhaps?
-
I have an Applescript that copies the text of a selected email into the frontmost outline document. This means that the script has two tell statements, the first to Apple Mail the second to OmniOutliner. Am I correct in thinking that when I rewrite this script using Javascript the new script will have to be written in the version that is described in the Script Editor dictionary or is there a way of mixing the two? Perhaps by using the encoded URL option.
-
How should I declare variables ? I ask because I have read that var can cause “namespace” issues and that let should generally be used. In an investigation of how to rewrite my Applescript I found the following JXA script :
'use strict';
var app = Application.currentApplication()
app.includeStandardAdditions = true
var Mail = Application('com.apple.mail')
var selectedMails = Mail.selection();
for (var aMail of selectedMails) {
app.displayDialog(aMail.subject());
}
This runs and can be run multiple times from script editor without any issues. Then I replaced all the var statements with let . It ran o.k. once but on the second run an error was raised to the effect that the variable was already defined. This is the opposite to what I was expecting which was that all variables should be destroyed at the end of the script i.e. the closing brace. Obviously I do not understand.
Lastly lets not even talk about semi-colons which are optional until they are not.
best wishes
Simon