home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-28 | 4.2 KB | 156 lines | [TEXT/Moml] |
- (* as_examples *)
- (* 1997Jul27 e *)
-
- (* example 1: using the Process.system() call to send mail *)
-
- load "Process";
-
- val mail_appl_name = ref "\"Eudora Pro 3.1.1\"";
-
- fun send_mail to subj msg =
- Process.system(
- "tell application " ^ !mail_appl_name ^
- "\n make message at end of mailbox \"Out\" of mail folder \"\"" ^
- "\n set field \"to\" of message 0 to \"" ^ to ^ "\"" ^
- "\n set field \"subject\" of message 0 to \"" ^ subj ^ "\"" ^
- "\n set field \"\" of message 0 to \"" ^ msg ^ "\"" ^
- "\n queue message 0\nend tell"
- );
-
- (*
- send_mail "e@flavors.com" "testing system()" "Hi. I'm testing mosml142.";
- *)
-
- (* example 2: using the Process.system() call to present dialogs *)
-
- load "Process";
-
- Process.system(
- "display dialog \"My Dialog\" with icon stop default answer \"Right!\"");
-
- (*
- display dialog anything -- title of dialog
- [default answer anything] -- default editable text
- [buttons list] -- list of up to three buttons
- [default button anything] -- name or number of default button
- [with icon anything] -- name or id of the icon to display
- [with icon stop/note/caution] -- display one of these system icons
- Result: reply -- record containing the button hit and text entered (if any)
- *)
-
- (* example 3: using AppleScript to present dialogs & get results *)
-
- load "AppleScript";
-
- val dlg = AppleScript.as_compile(
- "display dialog \"My Dialog\" with icon stop default answer \"Right!\"");
-
- AppleScript.as_run_script dlg;
-
- (* example 3: AppleScript compile error *)
-
- load "AppleScript";
- load "Int";
-
- val bogusOSAID = AppleScript.as_compile "";
-
- val dlg2 = AppleScript.as_compile(
- "display dialog \"My Dialog\" with icon note buttons \"Yes\", \"No\"" ^
- "default answer \"Right!\"")
- handle AppleScript.AppleScriptErr (n,s) =>
- ( print (Int.toString n ^ " " ^ s); bogusOSAID);
-
- AppleScript.as_run_script dlg2
- handle AppleScript.AppleScriptErr (n,s) => (Int.toString n ^ s);
-
- (* example 4: AppleScript compile error corrected; dialog with buttons *)
-
- load "AppleScript";
-
- val dlg2 = AppleScript.as_compile(
- "display dialog \"My Dialog\" with icon note buttons {\"Yes\", \"No\"}" ^
- "default answer \"Right!\"");
-
- AppleScript.as_run_script dlg2
- handle AppleScript.AppleScriptErr (n,s) => (Int.toString n ^ s);
-
- (* example 5: Speech provided with Scripting Tools *)
-
- load "Process";
- load "AppleScript";
-
- Process.system( "speak \"Good night Irene.\"" );
-
- fun speak what =
- AppleScript.as_run_text ( "speak \"" ^ what ^ "\"")
- ;
-
- speak "My name is Tobar Radar Robot.";
- speak "My name is Toe bar Ray dar Ro bot.";
- speak "Hello, Megan and Doug!";
- speak "Good night Irene.";
-
- fun speak_with voice what =
- AppleScript.as_run_text ( "speak \"" ^ what ^ "\" voice \"" ^ voice ^ "\"")
- ;
-
- (* example 6: using return results, with Speech *)
-
- load "AppleScript";
- load "Substring";
-
- AppleScript.as_run_text "list voices";
-
- (* handy function to convert AS text list result to ml str list *)
-
- fun as_list_elements s =
- let open Substring
- val ss = all s
- val ln = size ss
- val s1 = dropl (fn c => c = #"{") ss
- val s2 = dropl (fn c => c = #"\"") s1
- val s3 = dropr (fn c => c = #"}") s2
- fun strrev [] r = r
- | strrev (h::t) r = strrev t ((string h)::r)
- fun lsd s =
- dropl (fn c => c = #"\"" orelse c = #" " orelse c = #",") s
- fun els s r =
- let val e = takel (fn c => c <> #"\"") s
- val z = size e
- in if z > 0
- then els (lsd (triml z s)) (e :: r)
- else strrev r []
- end
- in if ln = (size s3 + 3)
- then els s3 []
- else []
- end
- ;
-
- fun speak_all_voices what =
- let val voice_list = as_list_elements (AppleScript.as_run_text "list voices")
- fun spk voice = (speak voice; (* say the voice name *)
- speak_with voice what; ())
- in app spk voice_list
- handle AppleScript.AppleScriptErr (n,s) =>
- print (Int.toString n ^ " " ^ s); ()
- end
- ;
-
- speak_all_voices "Hello, Megan and Doug!";
-
- (* example 7: miscellaneous stuff *)
-
- load "AppleScript";
-
- AppleScript.as_run_text( "(scripting additions folder) as text");
-
- AppleScript.as_run_text
- "(((scripting additions folder) as text) & \"Speech\")";
-
- AppleScript.as_run_text
- "list terminology file (((scripting additions folder) as text) & \"Speech\")";
-
- (* *)
-
-