drop-in script

This is a script that I found on the net and I thought if I add the “on open” command will make it work. It doesn’t seem to generate and error.

Could anyone suggest a code to make it work and why it doesn’t work.

on open target_folder

tell application "Finder"
	set files_ to count files of entire contents of target_folder
	set folders_ to count folders of entire contents of target_folder
	
	display dialog ("Path: " & POSIX path of target_folder) & return & return & ¬
		"Files: " & files_ & return & "Sub-folders: " & folders_ & return & ¬
		"Total ItemCount: " & (files_ + folders_) buttons ¬
		{"OK"} default button 1 giving up after 5
end tell

end open

Not your fault, the input just needed to be coerced as alias.

on open target_folder
	tell application "Finder"
		set files_ to count files of entire contents of (target_folder as alias)
		set folders_ to count folders of entire contents of (target_folder as alias)
		display dialog "Path: " & (POSIX path of target_folder) & "
		
" & "Files: " & files_ & "
" & "Sub-folders: " & folders_ & "
" & "Total ItemCount: " & (files_ + folders_) buttons {"OK"} default button 1 giving up after 5
	end tell
end open

Hi,

the parameter of the open command is always a list of aliases


on open target_folder
	tell application "Finder"
		repeat with oneFolder in target_folder
			if class of item (oneFolder as text) is folder then -- check the class of the item
				set files_ to count files of entire contents of oneFolder
				set folders_ to count folders of entire contents of oneFolder
				display dialog ("Path: " & POSIX path of oneFolder) & return & return & ¬
					"Files: " & files_ & return & "Sub-folders: " & folders_ & return & ¬
					"Total ItemCount: " & (files_ + folders_) buttons ¬
					{"OK"} default button 1 giving up after 5
			end if
		end repeat
	end tell
end open

this method will cause an error while dropping more than one item.

I know, don’t think that more than 1 will but yeah.

Many thank to you Richard.

Regards,
Tommy

The book didn’t mention anything about the open command parameters.

Thank you so much Stefan. You are always helpful

Best regards,
Tommy