attaching scripts to folders

So apparently I am an idiot cause I just don’t get attaching a script to a folder, to be called by a new file creation. this might take a little to explain what has me so confused. oh and it’s Mac OS 9.0.4 and Apple script 1.4.3

so I am confused
I will use an example of what has me so confused from one of the other threads here

on adding folder items to theFolder after receiving theAddedItems
repeat with thisItem in theAddedItems
set thisItem to thisItem as alias–I was missing this, had to define each as an alias instead of a referenced item
tell application “Finder”
set thisItemName to the name of file thisItem
end tell
end adding folder items to

now, I can grasp parts of this but what I don’t get is: “theFolder” is listed in the first line and never refered to again. what is it? is it the folder this is attached to? if so does it need the full path, or does this script need to reside in the folder that contains the folder I want? what “does set thisItem to thisItem as alias” mean? how does an alias differ from the item itself? what does this help do or prevent?

Thanks for any help you guys can shed on ths subject.
confused new scripter

Chris

Correct Chris, theFolder is actually a reference to the folder the script is attached to.

No and no. The script can reside anywhere you wish. Once you attach it to a folder it remembers where the script is - no file path to the script or folder is needed.

In this case the script does not use the variable theFolder, it is probably adapted from a script that did use it either to move a file from or to it, or for some other reason where the folder is needed. BTW, theFolder is set to something like:

depending on your folder.

When you declare, repeat with thisItem in theAddedItems the script repeats with just that. Each item that was added, item 1, item 2, item 3. Coercing the item to an alias is letting your mac know you want to rename that alias, not item 1, 2 or 3 in the list of added items.

Incidentally, I know you may have just thrown that example together for an example but just in case, you missed the end repeat - it would not compile for me. Here it is with the end repeat.

on adding folder items to theFolder after receiving theAddedItems
	repeat with thisItem in theAddedItems
		set thisItem to thisItem as alias --I was missing this, had to define each as an alias instead of a referenced item 
		tell application "Finder"
			set thisItemName to the name of file thisItem
		end tell
	end repeat--this is the line that was missing.
end adding folder items to

Hope this helps. You are not an idiot - nobody here was born an expert.

[quote=“Mytzlscript”]

Correct Chris, theFolder is actually a reference to the folder the script is attached to.

No and no. The script can reside anywhere you wish. Once you attach it to a folder it remembers where the script is - no file path to the script or folder is needed.

after reading your message, I realized what part of this is confusing me. how does the OS know to pass the new file creation to the script? I don’t see any obvious trigger. you mention “once it is attached” is that done on script compile? is there a visual queue that tells me that yes indeed the script is attached to the folder?

Chris

thanks to Mytzlscript and the application Smile (the color coding and line by line checks) really help me out with the correction of my problems and most especially the syntax which was F***ing me up
for those curious this script requires the folder actions plus extension and it looks like:

set theFolder to alias “blue:System Folder:PrintMonitor Documents:EPSON Spool Folder6:”
on adding folder items to theFolder
tell application “Finder”
set spoolfiles to name of the first file of folder “Epson Spool Folder6” of folder “PrintMonitor Documents” of folder “System Folder” of disk “blue”
end tell
tell application “Finder”
activate
mount volume “volumename” on server “server-name” in AppleTalk zone “appletalk-zone” as user name “myname” with password “mypassword”
select file spoolfiles of folder “EPSON Spool Folder6” of folder “PrintMonitor Documents” of folder “System Folder” of startup disk
copy selection to disk “logging”
put away disk “logging”
end tell
end adding folder items to

again my great thanks for your help Mytzlscript. you gave me the tip over the hurdle.
Chris