"Can't get item 1..."

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. :slight_smile: 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?

This may do the job:

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"
	repeat with aFile in pdfFiles
		open aFile using application file id "DStf"
	end repeat
end tell

The line “open…” instructs the Finder to open each file using the application whose “creator type” is “DStf” → DropStuff.
About your code, two things: when you use the formula “repeat with i in thisList”, the variable “i” in each iteration contains a reference to an item in the list. For example:

repeat with i in {1, 2, 3}
	i
end repeat
--> item 3 of {1, 2, 3}

Some apps may follow the reference and get the value 3 from the item 3 of {1, 2, 3}. Other won’t understand the reference.
A workaround:

repeat with i in {1, 2, 3}
	contents of i
end repeat
--> 3

Or:

set myList to {1, 2, 3}
repeat with i from 1 to count myList
	myList's item i
end repeat
--> 3

Also, seems that you were passing StuffIt Deluxe the name of the files, but you must provide, according to its dictionary an alias (or list of such). That is: alias “path:to:file.pdf”, instead of “file.pdf”.

Your re-write worked perfectly. Thanks a lot! I knew I was making it too complicated.