Script to copy the parent folder of a file or alias place in a dropbox

Hi, I’m trying to develop a script to take affect when a alias of a certain document file type is dropped into a drop box. It then copies the parent folder of the alias into another location.

Here’s the script I have come up with so far:

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		
		-- Gets alias which has been added
		set f_sel to added_items as alias
		
		-- Gets type type
		set f_type to file type of f_sel
		
		-- Gets file path
		set f_path to f_sel as alias
		
		-- Gets folder for enclosed file
		set f_parent to container of f_path as string
		
		if f_type = "PDF " then
			duplicate (f_parent as alias) to folder (":Users:james:Desktop" as alias) with replacing
			
		end if
	end tell
end adding folder items to

When I’m running it through the script editor it works fine. However when I save this as a folder action to my drop box. Instead of copying the parent folder of the alias, it copies the dropbox folder.

Has anybody got a clue?

Thanks :smiley:

Hi,

are you talking about a Finder alias file (which points to an original file) or an (AppleScript) alias.
Alias is not equal to alias.

I’m wondering that your script is working at all:
added_items is a list of (AppleScript) aliases, your script will probably fail, if more than one item is added to the folder
try this


on adding folder items to this_folder after receiving added_items
	repeat with oneItem in added_items
		tell application "Finder"
			if file type of oneItem is "PDF " then
				duplicate (container of oneItem) to desktop with replacing
			end if
		end tell
	end repeat
end adding folder items to

Notes:
there are a few useless coercions:
set f_sel to added_items as alias – > added_items is a list of aliases anyway
set f_path to f_sel as alias → a single item of the list is also an alias

In a Finder tell block the desktop of the current user can be specified just by desktop

Thanks. Yep I have alot to learn.