Smile Dictionary
About the Guide to Smile dictionary
Below is given a summary of the dictionary of Smile. Refer to the dictionary itself for the syntax of any command, and for exhaustivity.
Smile's dictionary includes commands which can be used in any general AppleScript context, for instance commands to do some automatized text processing, and commands specifically needed to handle Smile's objects (windows, dialog boxes ...).
Standard AppleEvents
open
: open the specified file(s)
The argument may be a string, an alias, a file specification, or a list of such.
----------------------------
open (navchoose file) --
you may choose multiple files
----------------------------
close
: close the specified window
You must absolutely provide the 'saving' parameter (yes / no / ask).
----------------------------
close window "Worksheet" saving ask
----------------------------
make new
: make a new object of the specified class
----------------------------
set theTempWind to make new text window with properties {name:"hello"}
----------------------------
delete
: delete an object, with no chance to save it
----------------------------
delete theTempWind
----------------------------
quit
: quit the application
----------------------------
quit
----------------------------
Remote script handling
execute
: run the script contained in a script window
----------------------------
execute window "My first script" --> returns the value returned by the script
----------------------------
check syntax
: check syntax of a script window
----------------------------
check syntax window "My first script"
----------------------------
Miscellaneous utilities
display
: return the direct object as a string
----------------------------
display (get class of window 1)
----------------------------
change
: replace all occurences of a substring in a document. The value returned contains the number of changes, so it can be used to count the occurrences of a given string in the text.
----------------------------
change "a" into "A" in window 2
-- {x, y} x = number of changes made, y = number of characters in the window, useful in a script to update the selection
----------------------------
Note : "change" works on a document, while "replace", a command of the
Satimage osax
, works on strings contained in AppleScript variables.
'change' is fast, and can be used on arbitrarily long pieces of text.
make new name
: return the current time as a string of 19 characters, in a format suitable as a Mac file name.
----------------------------
set theName to make new name
----------------------------
-- "01/01/00, 21h52'05s"
extract column
: extract a column out of a table
Comments
The table is supposed to be tab-separated (
), with rows separated by carriage return characters (
). The result is returned as a list separated by carriage return characters. You can also obtain the result "as list".
----------------------------
extract column 2 in theTable as list
----------------------------
remote info for
: locate an alias on the network
----------------------------
remote info for alias theAliasFileAlias
----------------------------
press key
: posts the said keyboard event to the frontmost application
Comments
Can be used, for intance, to drive a non-scriptable application.
The sample makes Script Editor (a non-scriptable application) run a new script.
----------------------------
tell application "Finder" to open application file id "ToyS"
press key "N" with modifiers {command down}
repeat with x in "display dialog \"hello word\""
press key x
end repeat
press key "R" with modifiers {command down}
----------------------------
find definition for
: finds the definition of a verb or a class
Comments
The search can target, either a scriptable application, or the scripting addition folder.
----------------------------
tell application "Finder" to get file "Finder" of system folder as text
find definition for "duplicate" in alias result
----------------------------
This will return the definition of "duplicate" as found in the Finder's diectionary.
throwerror
: same as AppleScript's 'error' command, but faster
Comments
A bug of certain versions of AppleScript makes it sometimes better to use 'throwerror' than 'error' to throw an error from within a script.
----------------------------
try
[ some lines ]
on error s number n
if n = -128 then throwerror number -128 -- propagate user cancelation
end
----------------------------
Navigation services
The commands below implement the Navigation Services non-modal interface. This means that you can toggle to another application while a Navigation dialog box is open.
navchoose file
: choose files
navchoose folder
: choose folder
navask save
: prompt for save
navnew file
: get a new file specification. Can display a custom menu.
navnew folder
: get a new folder specification. Can display a custom menu.
Clipboard commands
undo
cut
copy
paste
The clipboard commands are window-specific. Each window has its own undo. So, these commands must be sent to windows:
----------------------------
tell window 1 to paste
tell window 1 to undo
----------------------------
Events sent automatically by Smile
These events are received on special occasions by the script of an object. If the object has an
object script
, it will receive the call, otherwise the call will be routed to the
class script
of the object.
prepare
: event sent to an object by the application just after the object has been created. Useful to proceed to the required initializations.
do menu
: event sent by the application when a menu item is selected
click in
: event generated by a click in an object
drop
: event generated by dropping
export
: return a description for the object dragged
store
: event sent by the application just before an object is saved. Useful to proceed to some updates before saving.
Summary of Smile object classes
We present here a selection of the properties of each object, those most often used.
Class basic object
: generic class which has the properties owned by each object
Properties:
class type
name
id
container
bounds
path name
visible
script
want idle
properties
Class application
: (inherits from basic object) the application program
Elements:
text window
script window
dialog
menu
menu command
Properties:
creator type
cursor
screen bounds
extensions path
user folder
dictionary
modifiers
clipboard
Class window
: (inherits from basic object)
Class text window
: (inherits from window)
Elements:
character
word
paragraph
text
run info
Properties:
selection
line width
console
store undo
update screen
Class script window
: (inherits from text window)
Class character
:
Properties:
text size
text font
text color
style
length
index
boundaries
paragraph index
word index
Class button
: (inherits from agent)
Class menu
:
Elements:
menu item
Properties:
name
enabled
checked
Class menu item
:
Properties:
name
enabled
checked
modifiers
shortcut
Text suite - Smile as a scriptable text editor
-
Basic descriptions
When refering to a substring of text contained in a Smile text document, you can use the following keywords :
character
,
word
,
paragraph
,
text / string
, and
selection
.
By default, these descriptors return lists of strings, like AppleScript does :
----------------------------
words 1 thru 2 of "Smile dictionary"
----------------------------
will [make AppleScript] return {"Smile", "dictionary"}, and :
----------------------------
words 1 thru 2 of window 1
----------------------------
will [make Smile] return {"Smile", "dictionary"}.
Now, you can coerce these expressions, either to
list
to get the offsets of the ends of the text chunk, or to
text
to get its contents. You can also coerce them into styled text, to get the text and its style altogether in one variable.
Note that it is more consistent to use the 'boundaries' properties to get the offsets of the ends of a text chunk, rather than coercing it to list - which may lead to unexpected behaviors in complex situations.
----------------------------
first character of paragraph after selection of window 1
----------------------------
--
"-"
----------------------------
words 1 thru 2 of window 1 as text
----------------------------
-- "Smile Dictionary"
----------------------------
words 1 thru 2 of window 1 as list
----------------------------
-- {0, 16}
----------------------------
boundaries of words 1 thru 2 of window 1
----------------------------
-- {0, 16}
----------------------------
set theText to words 1 thru 2 of window 1 as styled text
----------------------------
-- "Smile Dictionary"
The variable 'theText' contains styled text, which can be copied into another text window.
The
selection
of a text window returns a list. It can also be coerced to text or to styled text.
-
Using the 'whose' clauses
By using the 'whose' (or 'where') clause, you can specify a text chunk as the first, or last, fulfilling some condition. Conditions are introduced by the keywords
whose
,
where
, and
which
. Example:
----------------------------
first word of (first paragraph of window 1 where it contains "first word")
----------------------------
-- "first"
-
Using the 'every' construction
A description using the 'every' keyword returns a list of such descriptions. The list contains the contents of the concerned text chunks. Instead, it can be coerced to 'list' to return their locations. Example:
----------------------------
(every paragraph of window 1 where it contains "chunk") as list
-- {{6484, 6720}, {6722, 6932}, {7785, 8122}, {8405, 8468}}
----------------------------
-
Using 'after' and 'before'
Use the
after
and
before
keywords to refer to a piece of text by its location with respect to another one.
----------------------------
paragraph after words 1 thru 2 of window 1
----------------------------
-- ""
----------------------------
paragraph after words 1 thru 2 of window 1 as list
----------------------------
-- {17, 18}
-
Getting and setting text and text properties
Both 'get' and 'set' operators (when it makes sense) can be applied to any property of such text description(s), or to their contents, or to the beginning / the end of their content(s). The properties of text are listed under the entry 'text' of the dictionary. Several examples are provided below.
----------------------------
get color of every paragraph of window 1 where it contains "About"
-- {{16000, 0, 32000}, {0, 0, 0}}
----------------------------
get paragraph index of first paragraph of window 1 whose text size is 12
-- 1
----------------------------
set end of (first paragraph of window 1 whose (length > 30)) to " :)"
----------------------------
set first word of window 1 where it is "Smile" to "Smile's"
----------------------------
set first paragraph of window 1 whose color is purple to "About it"
----------------------------
Math library
cos
sin
acos
asin
tan
atan2
atan
sqrt
ln
log10
exp