-
-
Save drhisham-code/fc2b33a1720ec443c0fcfe900c106c36 to your computer and use it in GitHub Desktop.
Click drag mouse to specific position and dimension via command line in Mac OS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env xcrun swift | |
| import Foundation | |
| let firstDelayUSec : useconds_t = 2000_000 | |
| let kDelayUSec : useconds_t = 500_000 | |
| func DragMouse(from p0: CGPoint, to p1: CGPoint) { | |
| let mouseDown = CGEvent.init(mouseEventSource:nil, mouseType:.leftMouseDown, mouseCursorPosition:p0, mouseButton:.left)! | |
| let mouseDrag = CGEvent.init(mouseEventSource:nil, mouseType:.leftMouseDragged, mouseCursorPosition:p1, mouseButton:.left)! | |
| let mouseUp = CGEvent.init(mouseEventSource:nil, mouseType:.leftMouseUp, mouseCursorPosition:p1, mouseButton:.left)! | |
| usleep(firstDelayUSec) | |
| mouseDown.post(tap:.cghidEventTap) | |
| usleep(kDelayUSec) | |
| mouseDrag.post(tap:.cghidEventTap) | |
| usleep(kDelayUSec) | |
| mouseUp.post(tap:.cghidEventTap) | |
| } | |
| func main() { | |
| let args = UserDefaults.standard | |
| let x = CGFloat(args.integer(forKey:"x")) | |
| let y = CGFloat(args.integer(forKey:"y")) | |
| let dx = CGFloat(args.integer(forKey:"dx")) | |
| let dy = CGFloat(args.integer(forKey:"dy")) | |
| let p0 = CGPoint(x:x, y:y) | |
| let p1 = CGPoint(x:x + dx, y:y + dy) | |
| DragMouse(from: p0, to: p1) | |
| } | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment