Although I have worked with Perl, Python, PHP, and others, I am having trouble with what I suspect is a very fundamental operation with AppleScript. It’s probably the simplicity that is stumping me. Anyway, as a first step with AppleScript, I am writing a short script that archives all .pdf files in a user-specified folder. I’m fairly certain the problem is the lack of a full path to the file being operated on, but I can’t put my finger on how to provide StuffIt with the full path. Here is the script and the output of the event log:
SCRIPT
set pdfFolder to choose folder with prompt "Choose a folder in which to work."
tell application "Finder"
set pdfFiles to every file in folder pdfFolder whose name ends with ".pdf"
set FileList to {}
repeat with aFile in pdfFiles
set temp to the name of aFile
set FileList to FileList & temp
end repeat
end tell
tell application "StuffIt Deluxe"
repeat with bFile in FileList
stuff bFile into pdfFolder
end repeat
end tell
EVENT LOG
tell current application
choose folder with prompt "Choose a folder in which to work."
alias "Macintosh HD:Users:john:Books:AppleScript:"
end tell
tell application "Finder"
get every file of folder (alias "Macintosh HD:Users:john:Books:AppleScript:") whose name ends with ".pdf"
{document file "AppleScript4AbsoluteStarters.pdf" of folder "AppleScript" of folder "Books" of folder "john" of folder "Users" of startup disk, document file "AppleScriptLanguageGuide.pdf" of folder "AppleScript" of folder "Books" of folder "john" of folder "Users" of startup disk, document file "Scripting Additions Guide.pdf" of folder "AppleScript" of folder "Books" of folder "john" of folder "Users" of startup disk}
get name of document file "AppleScript4AbsoluteStarters.pdf" of folder "AppleScript" of folder "Books" of folder "john" of folder "Users" of startup disk
"AppleScript4AbsoluteStarters.pdf"
get name of document file "AppleScriptLanguageGuide.pdf" of folder "AppleScript" of folder "Books" of folder "john" of folder "Users" of startup disk
"AppleScriptLanguageGuide.pdf"
get name of document file "Scripting Additions Guide.pdf" of folder "AppleScript" of folder "Books" of folder "john" of folder "Users" of startup disk
"Scripting Additions Guide.pdf"
end tell
tell application "StuffIt Deluxe"
stuff "AppleScript4AbsoluteStarters.pdf" into alias "Macintosh HD:Users:john:Books:AppleScript:"
"StuffIt Deluxe got an error: Can't get item 1 of {"AppleScript4AbsoluteStarters.pdf", "AppleScriptLanguageGuide.pdf", "Scripting Additions Guide.pdf"}."
Would someone be kind enough to point out the obvious?