Right Click Contextual Menu

Hi. Not sure whether this can be done…

What I want to do is get the values of a right click menu from a given folder then action that task. i.e.

set x to contextMenu from folder foo

– {menu item 1, menu item 2,…}

action menu item 1

any ideas?

Select the folder or the file in the Finder and run this:


tell application "Finder"
	activate
	tell window 1
		set oldView to current view
		if oldView is icon view then set current view to list view
	end tell
end tell

tell application "System Events" to tell application process "Finder"
	set theSelection to value of attribute "AXFocusedUIElement"
	tell theSelection to perform action "AXShowMenu"
end tell

tell application "Finder"
	activate
	tell window 1
		if oldView is icon view then set current view to icon view
	end tell
end tell

NOTE: The contextual menu in icon view was shown incomplete so I added if blocks to get all correct.