• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: run script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: run script


  • Subject: Re: run script
  • From: has <email@hidden>
  • Date: Thu, 25 Oct 2001 14:18:40 +0100

Nicolas Descombes wrote:

>Hello,
>
>I'm french and I'm sorry for my english.

Way better than my French.:)


>I would want, with a dialog box, enter a formula with one or more variables.
>I tried with this script but AppleScript wants that I define the variable
[snip]
>How can I do to define the variable and obtain a result for my formula


The following script allows you to type in one or more lines of script by
using semi-colons to indicate returns (since you can't use returns in the
dialog), eg:

set x to 5; set y to 3; x div y

--> 1

If you need to use semi-colons normally then change this character to
something else.

I've also included some basic error trapping.

======================================================================

property yourDelim : ";" --character used to break statements

try
set Dialogue_2 to display dialog "Type formula

Use ';' to separate statements, e.g.
set x to 2; x+x" default answer ""

--trap error if user clicks "Cancel"
on error errorMsg
error errorMsg
end try

set Formula to text returned of Dialogue_2

--replace all semi-colons with returns
set AppleScript's text item delimiters to {yourDelim}
set Formula to every text item of Formula
set AppleScript's text item delimiters to {return}
set Formula to Formula as text
set AppleScript's text item delimiters to {""}

try
set total to (run script Formula)

--trap any errors in processing script
on error errorMsg
error errorMsg & return & return & Formula
end try

======================================================================

HTH

has


  • Follow-Ups:
    • Re: run script
      • From: "Bob.Kalbaugh" <email@hidden>
  • Prev by Date: Can't Wait
  • Next by Date: Re: any way to tell if a script has a 'return' statement?
  • Previous by thread: Re: run script
  • Next by thread: Re: run script
  • Index(es):
    • Date
    • Thread