Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript right click a file

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
like image 547
James Avatar asked Aug 21 '13 06:08

James


1 Answers

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/

like image 200
adamh Avatar answered Sep 27 '22 21:09

adamh