Satimage Previous | Next
Tracking execution
Home Documentation Smile AppleScript terminals Using AppleScript in Smile Tracking execution  
Smile offers several commands that you can insert in your script to have it provide information while it is running. Those commands work in AppleScript terminals as well as in Smile's script windows, the windows for editing regular scripts and applets.
log some_variable
prints some_variable to the Console, in a new line, and brings the Console to the front. The Console automatically opens if needed. If some_variable is not a string, log forces a coercion to a string: you can log complex types such as dates, lists and records.
msg(some_variable)
prints some_variable to the Console, in a new line, and brings the Console to the front. The Console automatically opens if needed. If some_variable is not a string, msg attempts to apply a standard AppleScript coercion into a string.
quietmsg(some_variable)
same as msg, but does not bring the Console to the front.
postit some_variable
displays some_variable into a floating Message window. some_variable should be a string, or an elementary type that can be coerced to string. To have your script close the Message window, insert postit "".
display some_variable
forces the coercion of some_variable into a string - but does not display it.

When you are developing a script which works on arrays of real or matrices, do use display to view rapidly their content in a human-readable form.

To force the Console to refresh its display after a msg or quietmsg command, insert smilepause 0 after the command.

Example
The simple example below computes the sum of the sizes of the files contained in a given folder. The script assumes that the_folder contains a valid alias to a folder. It first builds the list of the files to process, that it prints to the Console. Then it launches the process of the files: the Message window displays a progress information under the form "Processing [file name], 2 out of 120". If some error occurs for some file (which could occur if the operation on the file was more complex), the script prints the file's name and the error message to the Console, brings the Console to the front (so that the user be notified) and proceeds with the next file. Once all files processed the script closes the Message window and returns the result, which will print to the Console.
postit ("Listing files ...")
smilepause 0
set the_files to (list files the_folder)
quietmsg(display the_files)
set curr_index to 1
set total_size to 0
set files_count to (count the_files)
repeat with the_file in the_files
    set the_info to (info for the_file)
    set the_name to name of the_info
    postit "Processing " & curr_index & " out of " & files_count & ", " & the_name & return & "Press 'esc' to stop."
    smilepause 0
    try
        set total_size to total_size + (size of the_info)
    on error err_str
        quietmsg("Error while processing " & the_name & ": " & err_str)
    end try
    set curr_index to 1 + curr_index
end repeat
postit ""
set the_msg to "Total size: " & total_size div 1024 & " KB"
dd(the_msg)
return the_msg


Import script
Version française
Copyright ©2008 Paris, Satimage