• 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: Creating new file etc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating new file etc


  • Subject: Re: Creating new file etc
  • From: Bill Hernandez <email@hidden>
  • Date: Fri, 13 Apr 2007 00:31:14 +0000


On Apr 13, 2007, at 12:22 AM, Bill Hernandez wrote:

-- +---------+---------+---------+---------+---------+--------- +---------+---------+
on write_to_file(this_data, path2check, append_data)
(*
path2check can be a text path, an alias file reference, or a posix path
*)
set f_posixPath to ""
try
set found_valid_choice to true
set which_class to class of path2check
if (which_class = alias) then
set path2check to (path2check as text)
else if ((which_class = string) or (which_class = Unicode text)) then
if ((offset of "/" in path2check) > 0) then
if (first character of path2check is "~") then
set path2check to ((path to home folder from user domain) & (characters 2 thru -1 of path2check)) as string
end if
set f_posixPath to path2check
end if
else
set found_valid_choice to false
end if

if (found_valid_choice) then
(*
set the target_file to the this_file as text
-- the variable (this_file) is undefined, you defined this_file outside the scope of the function
*)
if (f_posixPath = "") then
set the open_target_file to open for access file path2check with write permission
else
set the open_target_file to open for access POSIX file path2check with write permission
end if
if append_data is false then
set eof of the open_target_file to 0
end if
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
else
set w_error to "Error (4388) : UnKnown class of path2check"
set aErrors to aErrors & w_error & return & path2check
display dialog w_error
end if
on error error_message number error_number
set w_error to "Error (4389) : " & error_number & ". " & error_message
set aErrors to aErrors & w_error & return
display dialog w_error
try
if (f_posixPath = "") then
close access file path2check
else
close access POSIX file path2check
end if
end try
return false
end try
end write_to_file
-- +---------+---------+---------+---------+---------+--------- +---------+---------+


The only change was that I forgot the line that shows

return false -- FORGOT TO RETURN FALSE HERE


-- +---------+---------+---------+---------+---------+--------- +---------+---------+
on write_to_file(this_data, path2check, append_data)
(*
path2check can be a text path, an alias file reference, or a posix path
*)
set f_posixPath to ""
try
set found_valid_choice to true
set which_class to class of path2check
if (which_class = alias) then
set path2check to (path2check as text)
else if ((which_class = string) or (which_class = Unicode text)) then
if ((offset of "/" in path2check) > 0) then
if (first character of path2check is "~") then
set path2check to ((path to home folder from user domain) & (characters 2 thru -1 of path2check)) as string
end if
set f_posixPath to path2check
end if
else
set found_valid_choice to false
end if

if (found_valid_choice) then
(*
set the target_file to the this_file as text
-- the variable (this_file) is undefined, you defined this_file outside the scope of the function
*)
if (f_posixPath = "") then
set the open_target_file to open for access file path2check with write permission
else
set the open_target_file to open for access POSIX file path2check with write permission
end if
if append_data is false then
set eof of the open_target_file to 0
end if
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
else
set w_error to "Error (4388) : UnKnown class of path2check"
set aErrors to aErrors & w_error & return & path2check
display dialog w_error
return false -- FORGOT TO RETURN FALSE HERE
end if
on error error_message number error_number
set w_error to "Error (4389) : " & error_number & ". " & error_message
set aErrors to aErrors & w_error & return
display dialog w_error
try
if (f_posixPath = "") then
close access file path2check
else
close access POSIX file path2check
end if
end try
return false
end try
end write_to_file
-- +---------+---------+---------+---------+---------+--------- +---------+---------+



Best,

Bill Hernandez
Plano,  Texas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Creating new file etc (From: Gregory White <email@hidden>)
 >Re: Creating new file etc (From: Bill Hernandez <email@hidden>)

  • Prev by Date: Re: Creating new file etc
  • Next by Date: Re: Creating new file etc (re-send due to small glitch)
  • Previous by thread: Re: Creating new file etc
  • Next by thread: Re: Creating new file etc (re-send due to small glitch)
  • Index(es):
    • Date
    • Thread