Before using this property, make sure to activate QuoEdit.
Though the data type is defined as ‘a list of anything’ in the dictionary, you don’t necessarily need to specify a list to set the value.
Getting value of clipboard
In QuoEdit, the basic data type is text. It returns a list of some types of data if the Clipboard contains text or an empty list if the Clipboard contains no text.*
After QuoEdit first gets the text, it searches the Clipboard for style information, reference (object specifier)**, apple event list and apple event record in the order. The type specifiers are 'TEXT', 'styl', 'obj ', 'list' and 'reco' respectively. (In many cases, types other than text will be not found.)
If you wish to get the value as a string instead of a list, add ‘as’ parameter specifying string.
get clipboard as string
But if the Clipboard doesn’t contain text, getting it as string results in error. (Don’t expect empty string.)
To get it as styled string, specify ‘styled text’ instead.
get clipboard as styled text
If the Clipboard does not contain the style information but text, plain text is returned in this case.
* | The Clipboard can contain empty string. Here the empty string is assumed to be text. |
** | If the reference value does not contain application’s information, it seems that AppleScript adds the application information of one from which AppleScript got the reference value. For example, the Finder copies reference value «folder "Internet" of disk "MyDisk"» to the Clipboard and if you get the value via QuoEdit’s ‘clipboard’, AppleScript adds «of application "QuoEdit"» to it. |
QuoEdit directly copies any types of specified data to the Clipboard unless the data type is list.
For example, when you execute the following script, the specified reference itself is copied to the Clipboard without resolving the object.
tell application "QuoEdit" activate set clipboard to paragraph 1 of document 1 end tellThis behavior might look scamped. But it allows you to use the Script Editor’s menu command “Paste Reference”.
set clipboard to (get paragraph 1 of document 1)This statement actually consists of two statements. The first gets the target text and the second copies the result value to the Clipboard.
tell application "QuoEdit" activate get {selection of document 1 as string, selection of document 1} set clipboard to result end tellIn this case, the text is common to every application and the reference can be used by the Script Editor (via “Paste Reference” menu command). Similarly, you can add any other information that is specific to other application(s) if you could make the data. For example, information that can be interpreted by a graphic application.
The data type (class) is ‘version’ type*, the same name as the property. Though the value is shown as a string in the result window of the Script Editor, the string is just for display purpose and it actually contains several properties that are undefined in AppleScript.
In AppleScript, the data of the ‘version’ type can be coerced to ‘string’ or ‘real’ type like the following.
version as string
version as real
To evaluate the version number, coercing it to real is recommended like the following because the string can be irregular in many cases.
tell application "QuoEdit" if version as real < 0.7 then display dialog "Too early version!" end tellOn the other hand, to evaluate the localization information, you have to coerce it to string.**
tell application "QuoEdit" if version as string ends with "J" then display dialog "This is a Japanese version." -- Actually, names of menus or menu items may be copied to variables here. end if end tellCurrently, QuoEdit is localized to Japanese and the version string contains “J” at the end like “1.0.0J” and the bug fixed version will be like “1.0.0r1J”.
* | In some applications (even in the Finder!), the value is returned as string. Actually, the data type of the ‘version’ property is defined as ‘version’ type by Apple Computer (in “Winter 1992 Apple Event Registry Errata”). |
** | You can also retrieve the region code (country code) from the version type data if you had the skill and maybe some osaxen (or if AppleScript defined the properties in the future). |
When you are going to do something on the front document, you would sometimes test the front document like the following.
if (document 1 exists) and (kind of window 1 is document) then
If you got tired of typing it, use the shortcut by application’s property ‘current window type’ like the following.
if current window type is document then
Currently ‘current window type’ can be four kinds of value; document, batch found, null and «class cdbx». But don’t rely on the value «class cdbx» that means a dialog box (movable modal dialog box). A class of dialog box won’t be defined explicitly, at least for a while.
Execution result
Contains result of a script last executed from QuoEdit. Note that the value is once disposed when this application runs the next script so that you can get the value only from external program such as the Script Editor or applet.
If the coercion is possible, you can get the value as desired type with ‘as’ parameter. But note that you cannot get it as text to display the value (like text in the result window of the Script Editor) in usual way.* To get such a text, make a document window with the initial data specifying ‘execution result’ property. See also description about ‘make’ command in this guide.
* | In older versions, you could get the display purpose text specifying “as string”. But that feature was obsoleted in version 0.71 because it’s not logical. |
When QuoEdit is launched, text item delimiters are initialized with {tab, return}.* Note that the initial value can be changed so that you should set the delimiters to the proper value before using ‘text item’ objects even if the value is same as the initial value.
If you are treating tab-delimited fields within each paragraph, only {tab} would be enough as the value.
set text item delimiters of application "QuoEdit" to {tab}
Of course you can simply write like the following in the ‘tell’ statements to QuoEdit.
set text item delimiters to {tab}
Always distinguish the application’s ‘text item delimiters’ from one of AppleScript.
As for the value in QuoEdit, up to eight delimiters are available but only 1-byte character is allowed. (On the other hand in AppleScript, only one text item delimiter is available but it can be string.)
* | In versions prior to 0.71, fixed to {return, tab}. |
In Macintosh user interface, not only document windows but also dialog boxes and floating pallets are “window”. In AppleScript terms of QuoEdit, however, “window” is restricted to two kinds of windows, that is, document window and batch find result window.
In other words, ‘window’ class object can be window for ‘document’ or ‘batch found’ (batch find result) in QuoEdit. So it is recommended to use the ‘document’ or ‘batch found’ class explicitly rather than ‘window’ class when you refer to a object open in the window, unless you are going to do common things about the windows.
Reference to the window object
If a script works with only the frontmost window, Index reference form (like window 1) must be enough. (This can be also applied to document class.)
But if the script works with two or more windows, using Name reference is more recommended because the index depends on the current front-to-back order.
But (again) how about the case that windows of the same name exist incidentally? To find out the specified window, QuoEdit searches windows in front-to-back order for the name so that it still depends on the order. So using ID reference form is more recommended.
(But if the windows order is apparent to you, Index reference would be still enough.)
‘Menu’ class of QuoEdit supports menus on the menu bar and submenus (and exceptionally a popup menu).
In QuoEdit, the menu on the menu bar is called “main menu” for convenience. Main menus includes File menu, Edit menu and so forth but not include Help menu and other system’s menus.
“Submenu” is a menu that is attached to another menu as its menu item so that it creates hierarchical menu.
Note that class of the main menus and submenus is completely equal though the behaviors are a little different. To determine the kind of menu in the scripting, use the ID that is described later.
Additionally to the main menus and submenus, QuoEdit exceptionally supports Font popup menu of Typeface dialog box as a menu object, so that you can get the names of the installed fonts:
name of every menu item of menu "Font" of application "QuoEdit"
In the other view point, a menu that is built in the application is called “standard menu” and a menu that is added externally is called “additional menu” in QuoEdit.
Reference to menu object
Inside the application, menus are basically referred by the menu ID. Similarly in the scripting features of QuoEdit, the basic reference form to the ‘menu’ class objects is ID reference form.
menu id 134 of application "QuoEdit"
However, you actually have to use index reference form for a reason.*
menu 134 of application "QuoEdit"
Note that the index of the menu object is always equal to the ID in QuoEdit and that is a special case.
The name reference to the ‘menu’ class object is also supported.
menu "Tools" of application "QuoEdit"
When the name was specified, QuoEdit searches menus from menu ID 137 to 1 and Font menu until the name is found. If the names of submenu conflict, therefore you may get unexpected menu object.
Unlike window objects, the IDs of the standard menus are always fixed.**
Menu name | Menu ID | |||||
File | 129 | |||||
Edit | 130 | |||||
Search | 131 | |||||
Window | 132 | |||||
Extras | 133 | |||||
Tools | 134 | |||||
Font | 256 | |||||
|
* | There is a problem of ID reference to menu object that it cannot be compiled directly in the ‘tell’ statement to QuoEdit because the menu class has a property named ‘menu ID’ that conflicts. Fortunately, the real index reference to the ‘menu’ objects (that counts them like 1, 2, 3...) is not supported in QuoEdit because the ‘count’ command cannot count the number of menus in this application. The filter reference to the ‘menu’ objects is therefore not supported. |
** | Menu ID can be changed in the future (though I will try not to change). So using variable for the menu ID is recommended in the script so that you can update the script later by just modifying a number. |
You can create up to three main menus using ‘make’ command. Note that the ‘name’ is always required.
make new menu with properties {name:"HTML"}
The additional menus are inserted between Tools menu and Window menu with the menu ID of 135, 136 and 137 in the order. You cannot use ‘at’ parameter to specify the position.
And a file in which the whole main menu’s data is saved is created in the Menus folder in QuoEdit’s folder (though empty in this point). The file is named with the menu title preceded by the menu ID. You can change the ID number or remove it later. The number just effects the position in the menu bar when the application launch.
You can also make the “Tools” menu if it is currently not in the menu bar. In this case, you can specify either ‘name’ or ‘menu ID’.
make new menu with properties {name:"Tools"}
make new menu with properties {menu ID:134}
You cannot make submenus as ‘menu’ class. To make submenu objects, use ‘menu item’ class instead.
make new menu item at end of menu "Tools" with properties ¬ {name:"My Signature", kind:submenu, required window type:document}Removing menu object
You can remove main menus by ‘delete’ command.
delete menu "Tools"
In this case, the menu definition file “Tools” is removed from the Menus folder and put into the Trash. The content of the definition file remains unchanged.
You cannot remove submenus as ‘menu’ class. To remove submenu objects, use ‘menu item’ class instead.
In this application, we call a menu item that is originally in the application “standard menu item”, and a menu item that is added externally “additional menu item”.
Note that ‘Menu item’ class in QuoEdit is mainly for the additional menu items. You can never change the properties of the standard menu items even if you could get some of the values.
Definitions of the additional menu items are saved in the definition file for the main menu in the “Menus” folder.
Properties of menu item class
Additional menu item objects in QuoEdit are categorized into the following kinds.
running script | runs attached script |
Finder opening | opens attached object by the Finder sending ‘open’ Apple event |
typing | types attached text string with ‘make’ Apple event |
tagging | removes and adds attached data with ‘tag’ Apple event |
submenu | a submenu |
divider | divides menu items into groups |
1) If the kind of the menu item is ‘running script’:
You can specify reference to a script file, reference to a folder, or data of a script object*. To specify reference to the file or folder, you can use string of relative path (that begins from QuoEdit’s folder) or alias.
If you specified a file or a script object and if the script was changed after the execution, the change is saved automatically. On the other hand, if you specified a folder, or specified file was not found, the menu item behaves like the Execute Script menu command (except that “Open Script” function is unavailable).
2) If the kind of the menu item is ‘Finder opening’:
Specify reference to a file or folder. You can use string of the relative path (that begins from QuoEdit’s folder) or alias. If you specified a folder, or specified file was not found, it shows a dialog box to choose a file to open. Launch Application and Let It Open menu items in the Extras menu are the examples.
3) If the kind of the menu item is ‘typing’:
Specify a string to be typed.
4) If the kind of the menu item is ‘tagging’:
Specify a list whose format is {{a, b}, {c, d}}. When the menu item is selected, it generates Apple event like the following to the application itself.
tag selection of document 1 with data {a, b} removing {c, d}
If you won’t remove any string, the second list {c, d} can be omitted. For example, attachment of Add Prefix menu item in the Tools menu is {{"> ", ""}}. And if won’t add any string, the first list {a, b} can be empty. For example, attachment of Remove Prefix menu item in the Tools menu is {{}, {"> ", ""}}.
5) If the kind of the menu item is ‘submenu’:
You cannot set attachment to any value. But you can get the value as a reference to a ‘menu’ class object.
6) If the kind of the menu item is ‘divider’:
Attachment is unavailable.
* | Try not to attach script object retrieved from a script that contains multiple script objects. When the desired script object is retrieved, the data size is unnecessarily large because the script object also includes data of all the brother script objects. (Why??) Attaching such script objects will waste memory and disk space to be saved. |
Value of ‘attachment type’ property is just the data type of the attachment that was actually attached and is saved in the menu definition file.
If the kind of the menu item is not submenu nor divider, the values of the following references are same.
class of attachment of menu item 1 of menu 134
attachment type of menu item 1 of menu 134
But using ‘attachment type’ property is faster as it gets the data type directly. And this property is necessary and useful, for example, when you refer to menu items by filter reference like the following.
every menu item of menu 134 whose attachment type is script
Optional info
1) If the kind of the menu item is ‘tagging’:
You can specify a class that is something symbolic for ‘tag’ event. Specify ‘paragraph’, ‘text’ or nothing.
If you specify nothing (or ‘null’), the menu item generates ‘tag’ event with no special option and the target to tag is current selection.
If you specify ‘paragraph’ class, it generates ‘tag’ event with ‘each paragraph’ parameter. And the target is still current selection.
If you specify ‘text’ (or ‘document’) class, it generates ‘tag’ event targeting “every text of document 1”.
2) If the kind of the menu item is ‘Finder opening’:
You can specify list of file types to be displayed in the Open dialog box. In QuoEdit, up to 16 file types are acceptable. For example, the ‘optional info’ property of Launch Application menu item in the Extras menu is set to {"APPL", "adrp", "APPC", "acdp"} that means application, alias of application, control panel application, and alias of one.
Required window type
If the kind of the menu item is ‘running script’, ‘Finder opening’ or ‘submenu’, you can specify one of window types. While the specified type of window is not in the front, the menu item is to be disabled.
The followings are available types. (As you see, the types are not necessarily window types.)
null | No window or any window is OK |
window | Document window or batch find result window |
document | Document window |
batch found | Batch find result window |
text | Document window whose edit type is text |
script | Document window whose edit type is script |
If the value is true, the menu item is to be disabled while:
◊ no character (or no hit) is selected
◊ front window is empty
respectively.
But if the kind of the menu item is ‘typing’ or ‘tagging’, the value is always false (even if you specified true) so that you don’t need to specify it.
Requiring clipboard
If the value is true, the menu item is to be disabled while the Clipboard does not contain text.
But if the kind of the menu item is ‘typing’ or ‘tagging’, the value is always false (even if you specified true) so that you don’t need to specify it.
Note that the Clipboard can contain empty string (that is zero byte length data of type 'TEXT') but ‘requiring clipboard’ property does not assume the empty string to be text so that the behavior of the menu item is compatible with the Paste menu command in the Edit menu.*
* | Contrarily, application’s property ‘clipboard’ assumes the empty string in the Clipboard to be text. In properties of menu item class, user interface is more important. |
You can create menu items by ‘make’ command in additional menus including the Tools menu and at under standard menu items in the Extras menu. The number of menu items are limited to 31 per menu.
make new menu item at end of menu "Tools" ¬ with properties {name:"Do It", kind:running script}The ‘at’ parameter is required to specify the position. If you are adding a menu item in a submenu, specifying ‘menu item’ object as the container is also available.
make new menu item at end of menu item "My Submenu" of menu "Tools" ¬ with properties {name:"Do It", kind:running script}And the important thing is specifying the properties. See the dictionary and descriptions above about the properties of ‘menu item’ class.
You can remove menu items by ‘delete’ command.
delete last menu item of menu "Tools"
In this case, the definition of the menu item is deleted from the definition file immediately and you cannot undo that.
Refers characters number of the text object* and that is compatible with AppleScript language.
To get the byte length of the text object, use another property ‘byte length’. (In 1-byte script systems, ‘length’ and ‘byte length’ are equivalent.)
* | Actually, there are many scriptable applications that resolve the ‘length’ of text object as the number of bytes. Also the old versions of QuoEdit defined the ‘length’ as byte length. But that should not be allowed, in my opinion, at least in 2-byte languages world. So, QuoEdit version 0.5 re-defined it according to the AppleScript language. If you have written scripts that refer to the ‘length’ property (as the byte length) and if the scripts are supposed to run also on 2-byte language text, please replace the ‘length’ with ‘byte length’. (Note that the ‘byte length’ is not standard term of AppleScript so that the term will not be compiled if it is out of ‘tell’ statement to QuoEdit.) But if you never edit Japanese, Chinese or Korean text, ‘length’ and ‘byte length’ are always equivalent so that old scripts work without modification. |
Refers position of the text object in the document in characters.*
To get the position in bytes, use another property ‘byte offset’. (In 1-byte script systems, ‘offset’ and ‘byte offset’ are equivalent.)
* | The old versions of QuoEdit defined the ‘offset’ as the byte position. But to keep compatibility with the unit of ‘length’ property described above, the version 0.5 re-defined it to be character position. If you have written scripts that refer to the ‘offset’ property (as the byte position) and if the scripts are supposed to run also on 2-byte language text, please replace the ‘offset’ with ‘byte offset’. But if you never edit Japanese, Chinese or Korean text, ‘offset’ and ‘byte offset’ are always equivalent so that old scripts work without modification. |
‘Font’ and ‘Size’ (point size) are usually properties of Text class. But in QuoEdit, they are properties of Document class because only one style is available in a document.
(Currently QuoEdit allows you to use ‘Font’, ‘Size’, ‘Leading’, ‘Script Code’ and ‘Writing Code’ as the properties of Text class. But they are never described in the QuoEdit’s dictionary. So don’t rely much on them as properties of Text class.)
Limitation of text length
Per AppleScript Language Guide, there is no limit on the length of strings except the memory available in the computer. But it seems that AppleScript as a software has a limitation on text length in some cases. For example, when a script does comparison with large text date, it shows the alert that tells that it cannot perform operation on text longer than 32KB.
And in the earlier systems, the data size of an Apple event (including the parameters) had been limited to 64KB.
However, if an application and AppleScript don’t send and receive the data of the text, there is really no limit on the length without the memory. (Of course, sending and receiving text via the Clipboard or files does not concern the limitation.)
For example, when you select a large text and the following test is executed, memory error might be returned or system error could actually occur (in my experience).
if selection as text is not "" then -- AppleScript gets the text and compares
To avoid the danger, test it like the following.
if 0 < (get byte length of selection) then -- tests the length of the text
And the following test is safe in QuoEdit.
if selection is not "" then -- QuoEdit does comparison and return the result
But in this case, memory to compare the text is temporarily used. And only option of how to compare uppercase/lowercase is available (with ‘filter ignores case’ property of application).
* | The format of «2-byte script code, 2-byte language code and text» is from definitions of Apple events (“Apple Event Registry: Standard Suites Version 1.0”). Another definition described in newer edition of “AppleScript Language Guide” is different from that. |
As for the text object of QuoEdit or object relevant to the text, the ‘best type’ is always ‘text’, whether it is paragraph, byte or even insertion point*.
As for the window object of QuoEdit, the best type is the kind of the window, that is, ‘document’ or ‘batch found’.
As for the other objects of QuoEdit, the best type is basically the same value as the ‘class’ property.
Best type would be useful to determine whether a reference refers to text in the document or not. For example, value of ‘selection’ of something can be reference to a part of contents of a document window or batch find result window so that the best type of the selection can be ‘text’ or ‘hit’.
* | Note that the AppleScript returns ‘string’ rather than ‘text’ when you ask the ‘best type’ («class pbst») of a string data that doesn’t belong to any application. |
In QuoEdit, if you changed ‘name’ of a document object that had been once saved in the file (document that has the file 1), the file is detached from the document. That is, the file is closed without saving and the document turns unsaved.
Similarly, if you changed Name of a Script object that has the file object, the file is detached from the script object.
If you wish to change the name of the document and if the document is saved in the file, ask the Finder to change the file name first, then ask QuoEdit the file information like “file 1 of document 1”. When QuoEdit noticed that the file information changed, it will immediately update the window title and so on.
Contents
‘Contents’ is a property of ‘document’, ‘text’, ‘selection object’ and so forth in QuoEdit and is used to refer to text in the document in many cases. In such cases, values of ‘contents’ and “every text” are equal. But using “every text” is rather recommended for a reason that follows, especially if the container is specified by the variable.
‘Contents’ is also a property of ‘reference’ class in AppleScript language. For example, suppose a variable theContainer in the following example is a reference to a document.
contents of theContainer
The value of this reference is still reference to the document rather than the text of the document. To refer to the entire text, you have to write the reference like one of the following.
contents of contents of theContainer
every text of theContainer
Selection
The value is a reference to the current selection. In QuoEdit, ‘application’ class, ‘document’ class and ‘batch found’ class has this property.
In many cases, both of the following two references refer to the selection of the front document.
selection -- selection of application
selection of document 1 -- selection of document 1 of application
(Actually in the old versions of QuoEdit, the both always referred to the selection of the front document.)
But the former can refer to a hit of a batch find result window if the window is open at the front. So, if you wish to refer to the selected text in a document, the later (that specifies the document) would be recommended.
Modifying the selection
This might be a little complex issue because a statement “set selection to ...” can have two meanings in some applications.
To select a text object, you could use both of the following ways also in old versions of QuoEdit (like the STE).
set selection of document 1 to paragraph 1 of document 1
select paragraph 1 of document 1
The former is one of the usages of “set selection to ...” but it is not supported anymore in QuoEdit for simplicity. Please always use ‘select’ command like the later to select an object.
Another usage of “set selection to ...” is to replace current selection with something new data and it is no problem in QuoEdit.
For example, in the old versions of QuoEdit, if the variable newData in the following statement was a reference to some text object that can be selected, the statement meant that the specified text object should be selected.
set selection of document 1 to newData
Currently, this statement always means that the selection is to be replaced with the newData in QuoEdit. If the variable newData is not text data, QuoEdit does effort to get it as text.
Of course, you can also write the statement like one of the following.
set contents of selection of document 1 to newData
make text with data newData at selection of document 1