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.