• 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: checking if variable is defined
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: checking if variable is defined


  • Subject: Re: checking if variable is defined
  • From: Andreas Amann <email@hidden>
  • Date: Sun, 21 Dec 2003 01:01:47 -0800

I use the following to test whether a variable is defined (theVar in the following example):

try
set tmpVar to theVar
on error
set theVar to "" -- or whatever you would want for default value
end try

- Andreas

I just noticed a little problem with this, my test to see if the variable "openedFile" is defined does not work. What is a proper way to check to see if a variable is defined?

- Ken

On Dec 21, 2003, at 2:29 AM, Graff wrote:


You need to open the file with write permission. You should also close it after you are done. It is also a good practice to put all this in a try block so that you can make sure that no matter what happens the file is closed:
-------------
set theFile to (path to desktop as text) & "mytextfile.txt"
try
set openedFile to open for access theFile with write permission
write "this text" to openedFile
close access openedFile
on error
if openedFile is not "" then
close access openedFile
end if
end try
-------------
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Dialects
  • Next by Date: Re: Sorting IP addresses - Progress
  • Previous by thread: Re: checking if variable is defined
  • Next by thread: Re: checking if variable is defined
  • Index(es):
    • Date
    • Thread