5
votes

Is there a command in apple script to right click a file and bring up the context menu?

I'm looking for something like

tell application "Finder"
    set theDesktopItems to every item of desktop
    right click item 1 of theDesktopItems
end tell
1
Which item do you want to choose from the popup menu? There might be a way to do it directly, without menu. - Mark
I just need to show the menu. Then the user will select the item manually. - James
@James Wondering if this worked out for you? If so it would be good to mark the question answered or share your result. - adamh

1 Answers

6
votes

This is a job for the System Events application. It can be used to reach menu items and their actions in most applications, even those that are otherwise not scriptable.

Try this:

tell application "System Events"
    tell process "Finder"
        set target_index to 1
        set target to image target_index of group 1 of scroll area 1
        tell target to perform action "AXShowMenu"
    end tell
end tell

Check this link for an overview of using System Events if you are so inclined: http://n8henrie.com/2013/03/a-strategy-for-ui-scripting-in-applescript/