Hi all! New to the boards, and fairly new to applescript. I have an app that I developed for a printing company using OS 9, that I am trying to port to OS X and I seem to be hitting my head against this unyielding brick wall.
This is a drag and drop application that takes a folder and searches for certain types of files inside and moves them to different locations on our server. Here is the problem I am having. I can’t seem to make this script go down more than one level deep. If I drop the file type on it, it sends it to the right place, but if I drop a folder, it tells me it “can’t get the class asty” of the folder I am dropping. Why wouldn’t it be able to to know that it is a folder I am dropping. I have tried simple file references and alias references and it doesn’t seem to make a difference.
This is a real problem for me because I actually need this script to search about five levels deep to be effective. As of right now I can’t even get it to go one.
Any help would be greatly appreciated!!!
Here is the script as it stands now:
property typelist : {"LWFN", "lwfn", "ffil", "tfil", "FFIL", "Font file", "font file", "font suitcase", "Font Suitcase", "PostScript� font", "Data-fork font suitcase", "OpenType� font", "TrueType� font", "PostScript� font"}
property extensionlist : {".ttf", ".otf", ".dfont"}
on open the_files -- this activates the file or folder dropped on the application
set destination to "Mac Imaging:Font Backup:"
set job_number to display dialog "Enter the Job Number" default answer "Job Number" -- this creates a dialog box for the user to enter a job number and sets the results of what the user enters to the variable job_number
set new_folder_name to text returned of job_number -- this sets the variable new_folder_name to the results of the previous dialog box
tell application "Finder"
activate
set item_list to items of folder "Font Backup" of disk "Mac Imaging" as string
if item_list contains new_folder_name then
set non_dupe_job_number to display dialog "That Job Number already exists. Font Backpack will now add the word new to the folder name you entered and continue. Font Backpack will attempt to copy the fonts again; however, if the fonts are still in use by Suitcase, they will not copy."
set new_folder_name to text returned of job_number -- this sets the variable new_folder_name to the results of the previous dialog box
make new folder at destination with properties {name:new_folder_name & " new"} -- this creates a folder named with the results from the dialog box, the job number
else if item_list does not contain new_folder_name then
make new folder at destination with properties {name:new_folder_name} -- this creates a folder named with the results from the dialog box, the job number
end if
end tell
try -- this tells the Finder to check if the file dropped is a font. If the file is a font, it duplicates the file onto the server "Mac Imaging" into a folder called "Font Backup"
tell application "Finder"
repeat with a_file in the_files
set the iteminfo to info for a_file
if (file type of a_file is in {"LWFN", "lwfn", "ffil", "tfil", "FFIL", "Font file", "font file", "font suitcase", "Font Suitcase", "PostScript� font", "Data-fork font suitcase", "OpenType� font", "TrueType� font", "PostScript� font"}) or (the file type of the iteminfo is in the typelist) then
duplicate a_file to folder (alias destination & new_folder_name)
end if
end repeat
end tell
end try
-- this entire try statement tells the Finder to search through the files dropped onto the application down two levels deep from the initial directory for any files that are fonts. If they are fonts, it duplicates the file onto the server "Mac Imaging" into a folder called "Font Backup"
tell application "Finder"
repeat with a_file in the_files
if kind of a_file is in {"folder", "FLDR", "fldr"} then
open a_file
repeat with b_file in a_file
set the iteminfob to info for b_file
if (file type of b_file is in {"LWFN", "lwfn", "ffil", "tfil", "FFIL", "Font file", "font file", "font suitcase", "Font Suitcase", "PostScript� font", "Data-fork font suitcase", "OpenType� font", "TrueType� font", "PostScript� font"} or (the file type of the iteminfob is in the typelist)) then
duplicate b_file to folder (alias destination & new_folder_name)
else if kind of b_file is in {"folder", "FLDR", "fldr"} then
open b_file
repeat with c_file in b_file
set the iteminfoc to info for c_file
if (file type of c_file is in {"LWFN", "lwfn", "ffil", "tfil", "FFIL", "Font file", "font file", "font suitcase", "Font Suitcase", "PostScript� font", "Data-fork font suitcase", "OpenType� font", "TrueType� font", "PostScript� font"} or (the file type of the iteminfoc is in the typelist)) then
duplicate c_file to folder (alias destination & new_folder_name)
else if kind of c_file is in {"folder", "FLDR", "fldr"} then
open c_file
repeat with d_file in c_file
set the iteminfod to info for d_file
if (file type of d_file is in {"LWFN", "lwfn", "ffil", "tfil", "FFIL", "Font file", "font file", "font suitcase", "Font Suitcase", "PostScript� font", "Data-fork font suitcase", "OpenType� font", "TrueType� font", "PostScript� font"} or (the file type of the iteminfod is in the typelist)) then
duplicate d_file to folder (alias destination & new_folder_name)
end if
end repeat
end if
end repeat
end if
end repeat
end if
end repeat
end tell
--in an effort to clean up a bit, this piece of script tells the Finder to close all the windows it opened while searching.
tell application "Finder"
close every window
end tell
-- this tells the application Suitcase to load the fonts from the intial set dropped onto the application
with timeout of [600] seconds
tell application "Extensis Suitcase X1"
activate
tell window "Add Fonts"
open the_files
end tell
end tell
end timeout
-- and to make life really good, this part tells the Finder to reopen the initial directory dropped onto the application if it was a folder
tell application "Finder"
open the_files
end tell
tell application "Finder"
activate
end tell
end open