What I wish to do is end up with a rtf file which contains the formatting that is in the filemaker field.
Here again the script as it stands.
tell application "Finder"
set homeFolder to (home)
set D_folder to folder "Documents" of homeFolder
end tell
tell application "Finder"
if not (exists folder "ReferenceWorks Bookmaker" of D_folder) then
make new folder at D_folder with properties {name:"ReferenceWorks Bookmaker"}
end if
end tell
tell application "FileMaker Pro Advanced"
set {fileName, this_Book} to {get data of cell "FileName" of current record, get data of cell "CompleteBook_cc" of current record}
end tell
set homeFolder to path to home folder as Unicode text
set BookmakerFolder to homeFolder & "Documents:ReferenceWorks Bookmaker:"
set this_file to BookmakerFolder & fileName & ".rft"
my write_to_file(this_Book, this_file, false)
on write_to_file(this_data, this_file, append_data)
-- I don't understand the var this_data, where is it declared?
-- it is declared in the opening line of the subroutine,
-- on write_to_file(this_data, this_file, append_data)
-- it is defined somewhere outside the subroutine
-- and it is passed to the subroutine like this:
-- my write_to_file(this_Book, this_file, false)
-- so, in this example this_Book contains a value (which we obtained from FMP )
-- and it is being passed to write_to_file() as the first parameter which is named this_data
-- why doesn't my script work?
-- when FMP sees "write" it thinks it knows what that means.
-- however FMP 's "write" is a property of objects, like fields, layouts and tables.
-- it has to do with user privileges: "write" means the object can be modified by the current user.
-- In FMP you would make an assertion, eg, "access of cell 2 of layout 1 is write"
-- which would be true or false
-- BECAUSE THIS ROUTINE IS BEING CALLED WITHIN FMP
-- WE HAVE TO CALL THE STANDARD ADDITIONS WRITE COMMAND USING RAW CODE
-- THE STANDARD ADDITIONS "WRITE" COMMAND IS «event rdwrwrit»
-- THE STANDARD ADDITIONS "READ" COMMAND IS «event rdwrread»
-- I keep a copy of the raw code "protected" by comments
-- in any script dealing with FMP because the AppleScript decompiler always
-- replaces «event rdwrwrit» with the word write
-- and every time that happens we have to replace the word write with the raw code «event rdwrwrit»
-- so that FMP doesn't get confused!
try
set the target_file to the this_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
«event rdwrwrit» this_data to the open_target_file starting at eof -- call "write" using raw code: «event rdwrwrit»
close access the open_target_file
return true
on error errMsg number errnum
display dialog errMsg & return & errnum
try
close access file target_file
end try
return false
end try
end write_to_file
Gregory White, Homeopath, M.A.H.A., Reg. AROH.
Australian & NZ Dealer for Kent Homeopathic Associates
---------------------------------
Mullumbimby (Near Byron Bay), Australia
Phone: +61 (0)2 6684 5557
Skypename: repertory.org