Closed4

JavaScript for Automationの基礎

四ツ山伊吹四ツ山伊吹

Object Specifierなるもの

Many objects in the JavaScript for Automation host environment refer to external entities, such as other applications, or windows or data inside of those other applications. When you access a JavaScript property of an application object, or of an element of an application object, a new object specifier is returned that refers to the specific property of that object.[1]

抄訳
JavaScript for Automation host環境における多くのオブジェクトは、外部にある実体を参照する。


Note: An object specifier is not the actual value of the external entity's property; it is a reference to the object.[1:1]

脚注
  1. https://developer.apple.com/library/archive/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW5 ↩︎ ↩︎

四ツ山伊吹四ツ山伊吹

Object Specifierの分類

https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/NavigateaScriptingDictionary.html#//apple_ref/doc/uid/TP40016239-CH77-SW1

Types of Terminology

The navigation pane of a dictionary includes the types of terms described in Table 12-1.

Type Icon Description
Suite 🆂 A suite is a grouping of related commands and classes. Apps often have a Standard Suite, which includes terminology supported by most scriptable apps, such as an open command, a quit command, and an application class.
Command 🅒 A command is an instruction that can be sent to an app or object in order to initiate some action. For example, delete, make, print are commands that are found in many scriptable apps. Many commands have parameters that specify the target object and control the behavior of the command.
Class 🅲🅴 A class is an object within an app, or an app itself. Mail, for example, has an application class, a message class, and a signature class, among others. Objects within an app sometimes contain other objects as elements. For example, in Mail, a mailbox objects can contain message objects as elements.
Property 🅿︎ A property is an attribute of a class. For example, the message class in Mail has many properties, including date received, read status, and subject. Some properties are read-only, while others are readable and writable.
四ツ山伊吹四ツ山伊吹

Object Specifierの継承と包含

https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/NavigateaScriptingDictionary.html#//apple_ref/doc/uid/TP40016239-CH77-SW1

Key Concepts

It’s important to understand the concepts of inheritance and containment when navigating a scripting dictionary.

Inheritance

In a scriptable app, different classes often implement the same properties. For example, in Finder, the file and folder classes both have creation date, modification date, and name properties. Rather than defining these same properties multiple times throughout the scripting dictionary, Finder implements a generic item class. Since files and folders are considered types of Finder items, these classes inherit the properties of the item class. In other words, any properties of the item class also apply to the file and folder classes. There are many other items in Finder that also inherit these same properties, including the disk, package, and alias file classes.

A class that inherits the properties of other classes can also implement its own properties. In Finder, the file class implements a number of file-specific properties, including file type and version. The alias file class implements an original item property.

In some cases, a class inherits properties from multiple classes. In Finder, an alias is a type of file, which is a type of item. Therefore, the alias file class inherits the properties of both the file and item classes, as shown in Figure 12-2.

Figure 12-2 In scripting, classes can inherit the properties of other classesimage: ../Art/Inheritance_2x.png

Containment

Classes of a scriptable app reside within a certain containment hierarchy. The application is at the top level, with other classes nested beneath. Finder, for example, contains disks, folders, files, and other objects. While files don’t contain elements, folders and disks can contain other folders and files. See Figure 12-3. Mail is another example—the application contains accounts, which can contain mailboxes, which can contain other mailboxes and messages.

Figure 12-3 In scripting, classes can contain other classes as elementsimage: ../Art/Containment_2x.png

When referencing a class, you must do so very specifically according to its containment hierarchy in order to provide the scripting system with context. To reference a file in Finder, you would specify where the file resides in the folder hierarchy. See Listing 12-1 and Listing 12-2. To reference a message in Mail, you would specify where the message resides in the mailbox and account hierarchy.

APPLESCRIPT

Listing 12-1 AppleScript: Referencing a file by containment hierarchy in Finder

tell application "Finder"
    modification date of file "My File.txt" of folder "Documents" of folder "YourUserName" of folder "Users" of startup disk
end tell
--> Result: date "Monday, September 28, 2015 at 10:10:17 AM"
JAVASCRIPT

Listing 12-2 JavaScript: Referencing a file by containment hierarchy in Finder

var Finder = Application("Finder")
Finder.startupDisk.folders["Users"].folders["YourUserName"].folders["Documents"].files["My File.txt"].modificationDate()
// Result: Mon Sep 28 2015 17:10:17 GMT-0700 (PDT)
このスクラップは2022/04/16にクローズされました