"more" menu

Ok, i’ve created an AS that i’d like to add to the menu that you get in a finder window when you right click. How do i do this. Yes, i know, there already is a copy function there. So lets say “if” i wanted to add it where would i hide it. I’m trying to reproduce my favorite window right click action, send to… Script is below.

--Handler to duplicate Files

on FileDup(source_file, destination_file)
	tell application "Finder"
		duplicate source_file to destination_file
	end tell
end FileDup


--set source as selected item and then defaults location to copy to as the Desktop.
tell application "Finder"
	set source_file to the selection as alias
	set destination_file to choose folder default location (path to desktop folder)
	
end tell

FileDup(source_file, destination_file)

Hi,

you can’t create a contextual menu item with AppleScript.

Alternatives are OnMyCommand or an applet dragged next to the search field in a Finder window.

Note: this line


set source_file to the selection as alias

will cause an error if you’re going to select more than one file

You should be able to create the desired contextual menu item using Automator.

For a “Copy To…” menu item you can use Automator’s Get Selected Finder Items action followed by Copy Finder Items. For a “Move To…” menu item, use Get Selected Finder Items followed by Move Finder Items. In either case, make sure to check Show Action When Run under Options, and from Automator’s File menu choose Save As Plug-in > Plug-in for: Finder. Once saved, access the workflow(s) under Automator in the Finder’s contextual menu, after right-clicking on selected Finder items.

You can also achieve the same result using an Automator workflow comprised of a single action – Run AppleScript – and save it, too, as a Finder Plug-in. One advantage of doing this is that the Choose-a-Folder dialog appears almost immediately, without having to first scroll down and select “Other” in a dialog window, as is the case with the workflow made up of Automator’s own built-in actions.

The example “Move To…” script below should be copied and pasted into a blank Run AppleScript action’s text area, and the single-action workflow should be saved as described above, with the exception that Show Action When Run under Options should be left unchecked. To create a “Copy To…” AppleScript-only workflow, simply replace each instance of the word “move” in the script with the word “duplicate.” Good luck.

“Move To…” contextual menu item script:

on run {input, parameters}
	tell application "Finder"
		set theseItems to selection
		set newFolder to choose folder with prompt "Please choose a destination folder..."
		set newFolderName to name of newFolder
		repeat with i from 1 to the count of theseItems
			set theName to name of item i of theseItems
			try
				move item i of theseItems to newFolder
			on error
				display dialog "An item named " & (ASCII character 34) & theName & (ASCII character 34) & " already exists in the " & newFolderName & " location. Would you like to replace it with the one you are moving?" & return & return & "Replacing the existing item will overwrite its current contents." with icon caution buttons {"Stop", "Don't Replace Item", "Replace Item"} cancel button "Stop"
				if button returned of result is "Replace Item" then
					move item i of theseItems to newFolder replacing yes
				end if
			end try
		end repeat
	end tell
	return input
end run

The AppleScript and workflows above were tested using Mac OS 10.4.11. Leopard users’ results may vary.

Both,
thanks for the posts.