Activate a script from mouse event, example

Thanks to Mark FX I got a other idea, sorry… but its so fun :slight_smile:
Lets make a mouse event to execute the screen saver…

The script need to be saved as applet and be running to work.

To test the script you move the mouse cursor to top right corner of your screen and wait 5 seconds.
And the screensaver will activate.

use framework "Foundation"
use framework "AppKit"
use scripting additions

on idle
	my activateScreenSaverFromMouseEvent()
	return 5
end idle

on activateScreenSaverFromMouseEvent()
	-- Get the Screen size
	set screens to current application's NSScreen's screens
	set theScreen to (screens's objectAtIndex:0)'s frame() -- main screen
	set {{x, y}, {width, height}} to {item 1 of theScreen, item 2 of theScreen}
	-- Get the mouse location
	set theLoc to current application's NSEvent's mouseLocation()
	if ((theLoc's x as integer) > (width - 10) as integer) and ((theLoc's y as integer) ≥ (height - 10) as integer) as boolean then
		tell application id "" to activate
		return 0
	end if
end activateScreenSaverFromMouseEvent