Scripting Notes: The Application Class

The top-level scripting object in any application is always the application itself. The application class can contain properties, specialized verbs (commands), and other scriptable elements (classes) that are contained by the application.

In the Notes scripting dictionary, the application class is found in two scripting suites: the Standard Suite, found in most scriptable applications, and the Notes Suite, specific to the Notes applicaion.

The application class in the Standard Suite contains a few standard application properties, such as name and version; a list of the standard application elements it contains, windows; and a list of standard verbs that can be directed at the application.

application n [see also Notes Suite] : The application’s top-level scripting object.

elements

contains: windows.

properties

frontmost (boolean, r/o) : Is this the active application?

name (text, r/o) : The name of the application.

version (text, r/o) : The version number of the application.

responds to

count, delete, exists, move, quit, print (window object only).

The application class in the Notes Suite contains only a list of the elements that belong to the application class itself: accounts, folders, notes, and attachments.

application n [see also Standard Suite] : the Notes application

elements

contains: accounts, folders, notes, attachments.

It is important to point out, that by belonging to the top-level application class, these elements (notes, folders, attachments) become available for high-level searches and actions, such as finding, moving, or deleting all notes/folders, or only the notes/folders matching a specific set of attributes.

Example Scripts

The following script examples demonstrate how to access and manipulate the application class elements. To open an example script in the AppleScript Editor application on your computer, click the script icon at the top left of an example script. (Requires OS X Mountain Lion)

Click to open example in the Script Editor application Find and Move Notes to Folder
This example demonstrates the use of the exists and move verbs with the notes and folder application elements.
tell application "Notes"
activate
if exists folder "Archive" then
move (every note whose name contains "January") to folder "Archive"
end if
end tell
Click to open example in the Script Editor application Delete Every Note
This example demonstrates the use of the delete verb with the notes application element.
tell application "Notes"
set the noteCount to the count of notes
display dialog "This script will attempt to delete " & noteCount & " note(s)." & ¬
linefeed & linefeed & "This action cannot be undone." buttons ¬
{"Cancel", "Continue"} default button 1 with icon 2
delete every note
display dialog "All notes deleted." buttons {"OK"} default button 1 with icon 1
end tell
Click to open example in the Script Editor application Delete Every Folder
This example demonstrates the use of the delete verb with the folder application element.
tell application "Notes"
activate
delete (every folder whose name is not "Notes")
end tell

IMPORTANT: Never delete the “Notes” folder from an account. Doing so can put the Notes application in a non-functioning state.

Click to open example in the Script Editor application Zoom Notes Window
This example demonstrates how to set the value of a property of the window application element.
tell application "Notes"
activate
set zoomed of window 1 to true
end tell
Click to open example in the Script Editor application Resize Notes Window
How to resize the notes window by setting the value of the bounds property of the window application element.
tell application "Finder"
copy the bounds of the window of the desktop to {x1, v1, screenWidth, screenHeight}
end tell
tell application "Notes"
activate
set the bounds of window 1 to {0, 0, screenWidth div 2, screenHeight}
end tell

TOP | CONTINUE