This sample script is an introduction to attachability in MacApp. When you run this script, the "On Close" handler is attached to each window, and when the window is closed, the event is first passed to the script to handle. This particular script will display the saving values (Did you ask it to save when you closed), modify the values, and return that value to MacApp in it's continue statement. This demonstrates how attachted scripts can greatly alter the behavior of a MacApp application. For instance, a user could attach this script to a "Form", and every time the document is saved, the default behavior is overridden and it is always backed up to a server.
Gotchas:
This script has a hard coded path location for saving the file. Replace the line:
set savingFile to a reference to file "MacApp:Desktop Folder:AttachedScriptSave"
to include a reference to your machine and folder.
Get All Menu Items
This simple script iterates over the menus and menu items and "gets" each of there properties. There was some confusion in previous versions of MacApp on the use of the Menu and Menu Item classes, so this script should jump-start developers on menu accessors.
To execute a menu command, use a command like this:
open menu item "print…" of menu "File"
Obviously, the method you choose as your specifer is up to you. This line could have read:
open menu item 9 of menu 2
Don't forget, the seperators and Apple menu are counted when doing absolute position object specification in AppleScript.