Scripting Additions Guide
Table Of Contents
CHAPTER 2
Scripting Addition Commands
Using Read/Write Commands 83
return (open for access file theFile)
end if
on error theErrMsg number errorNum
try
--if error is -43, the user can choose to create the file
display dialog "The file: " & theFile & " does not exist" ¬
buttons {"Create It For Me", "Cancel", "Ok"} ¬
default button 2
if button returned of the result is "Ok" then
return errorNum
else
--create the file
if writePermission is true then
return open for access file theFile ¬
with write permission
else
return open for access file theFile
end if
end if
on error theErrMsg number theErrNumber
return theErrNumber
end try
end try
end OpenFileIfItExists
--set a variable to the file you want to open or create
set fileToOpenOrCreate to "Hard Disk:Test File One"
set z to OpenFileIfItExists(fileToOpenOrCreate, true)
if z < 0 then
--OpenFileIfItExists returned an error
display dialog the result
else