-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.2: adding private window capabilities
- Loading branch information
1 parent
fa9c9bb
commit d6bb51e
Showing
11 changed files
with
144 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// KeyPress.swift | ||
// Sessions Extension | ||
// | ||
// Created by Alex Perathoner on 24/01/2020. | ||
// Copyright © 2020 Alex Perathoner. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
//import ScriptingBridge | ||
|
||
|
||
class KeyPress { | ||
static let src = CGEventSource(stateID: .hidSystemState) | ||
static let commandControlMask = (CGEventFlags.maskCommand.rawValue | CGEventFlags.maskShift.rawValue) | ||
static let commandControlMaskFlags = CGEventFlags(rawValue: commandControlMask) | ||
|
||
static let loc: CGEventTapLocation = .cghidEventTap // kCGSessionEventTap also works | ||
|
||
static func simulateCmdShiftN() { //should open new private window | ||
|
||
//safari.activate() //just to be sure -> replace by the postToPid | ||
|
||
let ndown = CGEvent(keyboardEventSource: src, virtualKey: CGKeyCode(0x2d), keyDown: true) | ||
let nup = CGEvent(keyboardEventSource: src, virtualKey: CGKeyCode(0x2d), keyDown: false) | ||
|
||
ndown!.flags = commandControlMaskFlags | ||
nup!.flags = commandControlMaskFlags | ||
|
||
let pid = getPid("com.apple.Safari")! | ||
if let ndown = ndown { | ||
ndown.postToPid(pid) | ||
} | ||
if let nup = nup { | ||
nup.postToPid(pid) | ||
} | ||
} | ||
|
||
static func getPid(_ ofAppWithBundleID: String) -> pid_t? { | ||
for i in NSWorkspace.shared.runningApplications { | ||
if (i.bundleIdentifier == ofAppWithBundleID) { | ||
return i.processIdentifier | ||
} | ||
} | ||
return nil | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.