Skip to content

Instantly share code, notes, and snippets.

@cprovatas
cprovatas / ActivateFileNavigatorSearch.applescript
Last active January 15, 2018 13:26
Make file navigator search bar active in Xcode 7,8,9
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
tell application "Xcode" to activate
if is_running("Xcode") then
tell application "System Events"
tell application "Xcode"
if (count of windows) < 1 then
@cprovatas
cprovatas / gist:6acef442fc43123bcd5d5e937dc7951a
Created January 6, 2018 21:57
Monitor Mouse Event for any arbitrary application on macOS in Swift
let callback: CGEventTapCallBack = { (tapProxy, eventType, event, refcon) -> Unmanaged<CGEvent>? in
debugPrint("we are monitoring the mouse event here")
return nil
}
let eventMask = (1 << CGEventType.leftMouseDown.rawValue) | (1 << CGEventType.leftMouseUp.rawValue)
let machPort = CGEvent.tapCreateForPid(pid: 40529, place: .tailAppendEventTap, options: .defaultTap, eventsOfInterest: CGEventMask(eventMask), callback: callback, userInfo: nil)!
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, machPort, 0)
@cprovatas
cprovatas / BlockBasedSelector.h
Last active June 1, 2023 01:34
Block-Based Selectors in Swift
//
// BlockBasedSelector.h
//
// Created by Charlton Provatas on 11/2/17.
// Copyright © 2017 CharltonProvatas. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface BlockBasedSelector : NSObject
@cprovatas
cprovatas / gist:8d4dafaa13da058da32b0f68f625b424
Created October 19, 2017 17:49
Solution to eliminate boilerplate code when Implementing Equatable for Associated Value Enums
import UIKit
protocol AutoEquatableEnum {
static func == (lhs: Self, rhs: Self) -> Bool
}
extension AutoEquatableEnum {
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.data == rhs.data
}