Problem with Filemaker/Applescript
Problem with Filemaker/Applescript
- Subject: Problem with Filemaker/Applescript
- From: "Pitcher, George" <email@hidden>
- Date: Wed, 13 Dec 2000 07:16:15 -0000
Hi all,
I'm having a problem with a script. Firstly a description of what I want to
achieve.
A filemaker script loops through a foundset and prints off front covers to
pdf which are then attached to stored PDF docs and then dropped into client
folders.
That part works fine. Interaction between FMP/AS/Acrobat.
The next step is to loop through the client folders, printing off a Schedule
of documents from Filemaker and dropping it into the folder.
The final loop ftps the folders to my NT box for clients to collect.
The problem seems to be at the second stage. I use a partition named "H"
(for simplicity) and FMP prints a PDF file to that using PrintToPDF, the
name having been stored in PrintToPDF's preferences folder. The next step in
the AS script is to move that PDF file into the appropriate folder and
basically, the script is trying to do it before the file has appeared and
gives the error "Can't get file "filename.pdf" of disk "H".
If I run the script from Script Editor it works. But not when it's being
done from Filemaker. I've tried 'ignoring application responses' which just
makes things not work even when running from Script Editor.
This is the only flaw in an otherwise great solution which saves my
assistand literally hours of 'manual' work.
Now this is my script:
=============================
tell application "Finder"
set pathname to "H:" -- where the folders are stored
--build a list of folders
copy name of every folder of disk pathname to FolderList
set foldercount to count of every folder of disk pathname
if foldercount > 0 then
if foldercount = 1 then
set foldername to FolderList
tell application "FileMaker Pro"
show (every record of layout "HEI_main" of database
"HeronCustomers.fp5")
show (every record of layout "HEI_main" of database ,
"HeronCustomers.fp5" whose cell "DeliveryBatch" is foldername)
set deliveryname to get ,
(cell "DeliveryBatch" of current record of database
"HeronCustomers.fp5")
set ftpFolder to get (cell "HEI_Folder" of current record of
database "HeronCustomers.fp5")
show (every record of document "HeronFlowmanager.fp5")
show (every record of document ,
"HeronFlowmanager.fp5" whose cell "DeliveryBatch" is foldername)
set filename to (deliveryname & ".pdf")
tell application "Finder"
set pathname2 to "HERON03:System Folder:Preferences:PrintToPDF
Output File Name"
make file at folder pathname2 with properties {name:filename}
end tell
--ignoring application responses
do script FileMaker script "AS_Schedule" of document
"HeronFlowmanager.fp5"
--end ignoring
tell application "Finder"
move file filename of disk pathname to folder foldername of disk
pathname
delete file filename of folder pathname1
end tell
end tell
else
repeat with i from 1 to foldercount
set foldername to item i of FolderList
tell application "FileMaker Pro"
show (every record of database "HeronCustomers.fp5")
show (every record of database ,
"HeronCustomers.fp5" whose cell "DeliveryBatch" is foldername)
set deliveryname to get (cell "DeliveryBatch" of current record of
layout ,
"HEI_main" of database "HeronCustomers.fp5")
set ftpFolder to get (cell "HEI_Folder" of current record of
layout ,
"HEI_main" of database "HeronCustomers.fp5")
show (every record of database "HeronFlowmanager.fp5")
show (every record of database ,
"HeronFlowmanager.fp5" whose cell "deliverybatch" is foldername)
set filename to (deliveryname & ".pdf")
tell application "Finder"
set pathname1 to "HERON03:System Folder:Preferences:PrintToPDF
Output File Name"
make file at folder pathname1 with properties {name:filename}
end tell
ignoring application responses
do script FileMaker script "AS_Schedule" of document
"HeronFlowmanager.fp5"
end ignoring
end tell
WaitTicks 20
move file filename of disk pathname to folder foldername of disk
pathname
delete file filename of folder pathname1
end repeat
end if
end if
end tell
set pathname to "H"
tell application "Finder"
copy name of every folder of disk pathname to FolderList
set foldercount to count of every folder of disk pathname
set Root_Dir to "/heron/"
set theHost to "146.176.81.127"
set usrId to "macftp"
set usrPw to "mac1"
if foldercount = 1 then
set file2ftp to FolderList
tell application "FileMaker Pro"
show (every record of database
"heroncustomers.fp5" whose cell "deliverybatch" is file2ftp)
set deliverynum to get ,
(cell "DeliveryNum" of current record of database
"HeronCustomers.fp5")
set ftpFolder to (get data cell "HEI_folder" of current record of ,
database "heroncustomers.fp5")
set cell "deliverynum" of current record of layout ,
"HEI_main" of database "HeronCustomers.fp5" to (deliverynum + 1)
end tell
set Sub_Dir to ftpFolder
set Full_Dir to Root_Dir & Sub_Dir as string
set path2file to "H:"
set thePath to path2file & file2ftp as string
log {opening:Full_Dir}
with timeout of 2000 seconds
tell application "Fetch 3.0.3" to make new transfer window at
beginning ,
with properties {hostname:theHost, userid:usrId, ,
password:usrPw as string, initial directory:Full_Dir}
tell application "Fetch 3.0.3"
activate
set {use passive mode, display server messages} to {true, false}
put into transfer window 1 item alias thePath text format Raw Data
binary format Raw Data
close transfer window 1
end tell
end timeout
tell application "Finder"
delete folder file2ftp of disk "H"
end tell
else
repeat with i from 1 to foldercount
set file2ftp to item i of FolderList
tell application "FileMaker Pro"
show (every record of database ,
"heroncustomers.fp5" whose cell "deliverybatch" is file2ftp)
set ftpFolder to (get data cell "HEI_folder" of current record of ,
database "heroncustomers.fp5")
set deliverynum to get ,
(cell "DeliveryNum" of current record of database
"HeronCustomers.fp5")
set cell "deliverynum" of current record of layout ,
"HEI_main" of database "HeronCustomers.fp5" to (deliverynum + 1)
end tell
set Sub_Dir to ftpFolder
set Full_Dir to Root_Dir & Sub_Dir as string
set path2file to "H:"
set thePath to path2file & file2ftp as string
log {opening:Full_Dir}
with timeout of 2000 seconds
tell application "Fetch 3.0.3" to make new transfer window at
beginning ,
with properties {hostname:theHost, userid:usrId, ,
password:usrPw as string, initial directory:Full_Dir}
tell application "Fetch 3.0.3"
activate
set {use passive mode, display server messages} to {true, false}
put into transfer window 1 item alias thePath text format Raw Data
binary format Raw Data
close transfer window 1
end tell
end timeout
tell application "Finder"
delete folder file2ftp of disk "H"
end tell
end repeat
end if
end tell
=================================
It might not be the most efficient script in the world, but I've only been
looking at AS for about 3-4 weeks. Any suggested improvements would be
welcomed.
Regards
George Pitcher
Technical Manager
HERON Project
Merchiston Learning Centre
Napier University
10 Colinton Road
Edinburgh EH10 5DT
Tel: 0131-455 2435
Fax: 0131-455 2249
www.heron.ac.uk