Script to invoke the contextual menu

Hello.

I was so tired of having to type stuff like applescript text item’s delimiters from AS Editor, so I thought I could have a script installed in its contextual menu to do that for me. Then I realized that there were no keyboard shortcut to invoke the contextual menu with.

First of all I looked for something that could actually make the click with the control key. I found cliclick by Carsten Blühm which can be downloaded from here.

Then I discovered this post to obtain the mouse position. Regulus solution works wonderful, I just did a minor change in order to get more "integer like coordinates.

[code]#import <AppKit/AppKit.h>
const char origin[] = “http://www.macscripter.net/viewtopic.php?id=33468 Regulus6633” ;

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSPoint mouseLoc = [NSEvent mouseLocation]; //get current mouse position
NSString* locString = [NSString stringWithFormat:@“%.0f, %.0f”, mouseLoc.x,mouseLoc.y];
printf(“%s\n”, [locString UTF8String]);

[pool drain];
return 0;
}[/code]
Then I created this AppleScript, which I have installed as a short key cut with Spark which can be downloaded from here

You will have to change the hardcoded paths to what suits your installation policy.


set mouseLoc to (do shell script "/usr/local/opt/MouseLocation")
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2}
set {mouseX, mouseY} to {(mouseX as integer), 1200 - (mouseY as integer)}

tell application "System Events"
    set frontProcessName to name of every process whose frontmost is true
    --    tell a to set aa to (get its name)
    set wnCount to count of windows of process named frontProcessName
    if wnCount > 0 then
        tell window 1 of process named frontProcessName
            set wnPos to its position
            set wnsize to its size
        end tell
        set {wnX, wnY, wnWidth, wnHeight} to {item 1 of wnPos, item 2 of wnPos, item 1 of wnsize, item 2 of wnsize}
        
        set {leftBound, RightBound, upperBound, lowerBound} to {wnX + 1, (wnX + wnWidth - 21), wnY + 50, (wnY + wnHeight - 51)}
        if mouseX ≥ leftBound and mouseX ≤ RightBound then
        else if mouseX < leftBound then
            set mouseX to leftBound
        else
            set mouseX to RightBound
        end if
        
        if mouseY ≥ upperBound and mouseY ≤ lowerBound then
        else if mouseY < upperBound then
            set mouseY to upperBound
        else
            set mouseY to lowerBound
        end if
    end if
end tell
set mouseLoc to "c" & mouseX & " " & mouseY
do shell script "/usr/local/opt/cliclick " & mouseLoc
set AppleScript's text item delimiters to astid

I have assigned it to shift cmd space Since all other combinations with space is taken. Logically it should really have been put on ctrl space, as you simulate a mouse click with a space, but there may be both quicksilver and spotlight on these places so.

Hank / Regulus6633 has enhanced his tool with a commandline switch which downloaded from here You must then rearrange the script a little. Since it with the command line switch automatically gives the position from the bottom of the screen the line:


set mouseY to 1200 - (mouseY as integer)

is then unnecessary and the script should work in every resolution.

Hi, McUser.

I presume that by “the contextual menu” you mean “Script Menu”. There’s a third-party alternative to this called FastScripts, which allows keyboard shortcuts.

Hello Nigel.

No. I meant the menu which comes up if you right click on something with the mouse, that is control-click in my case since I have only one mouse button.

Edit:It is especially useful for gaining access to the services menu, since there is a lot of “clicking” to getting there; now I hit shift cmd space, opt S, and some few arrow down, then a space, the most nice thing is that you don’t miss with the mouse on the first try. :slight_smile:

I want Fast menus anyway, this is for just getting the menu up without moving fingers from keyboard, which is not a true success, because I need to amend the script to move the mouse pointer within the window that has focus, in order for it to work as expected.

Any way it works from any app which has a right click menu as it is today.
I’ll fix this real soon.

Ah, right. I didn’t know there was one. :rolleyes: And having now tried it, I shall probably forget it again. :wink:

Hello.

Each to his own. :slight_smile: I sometimes finds useful stuff in the services menu, like opening apps for editing. But I think the “Computer’s” Script Editor script’s folder! in Snow Leopard is great! -Every thing you put into that one will pop up in the “contextual menu”! So I can select a block of text while I edit, then I can invoke the right click menu, and then I can select a script by the arrow keys, then run it by pressing space, which inserts some code on the selected block, this will break most of the selections, but the clipboard is on small step away. :slight_smile:

It now “gathers” the mouse cursor into the active window before it opens the contextual menu. In at least all scriptable apps. I think it will generate a run time error in the others, -and I will mend that too. :slight_smile:

FYI: I mentioned to you earlier about a new mouse tool that I was about to release. Today I released it and it might be some help to your script. It can do a bunch of stuff. You can see about it here.

'Thanks Hank.

I’m very busy at the moment, but will come back to you asap with something. (Working my ass on rather than off. :wink: