Created
August 13, 2017 03:00
-
-
Save KrisYu/dfafec87e6d847d28378039d7ee8fce5 to your computer and use it in GitHub Desktop.
capture screen using terminal commands in swift
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
public func caputreRegion(toURL fileUrl: URL) -> URL { | |
let fileUrlPath = fileUrl.path | |
let task = Process() | |
task.launchPath = "/usr/sbin/screencapture" | |
task.arguments = ["-i", "-r", fileUrlPath] | |
task.launch() | |
task.waitUntilExit() | |
return fileUrl | |
} | |
func captureWindow(toURL fileUrl: URL) -> URL { | |
let fileUrlPath = fileUrl.path | |
let task = Process() | |
task.launchPath = "/usr/sbin/screencapture" | |
task.arguments = ["-w", fileUrlPath] | |
task.launch() | |
task.waitUntilExit() | |
return fileUrl | |
} | |
func captureScreen(toURL fileUrl: URL) -> URL { | |
let fileUrlPath = fileUrl.path | |
let task = Process() | |
task.launchPath = "/usr/sbin/screencapture" | |
task.arguments = [fileUrlPath] | |
task.launch() | |
task.waitUntilExit() | |
return fileUrl | |
} | |
let url = URL.init(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Desktop").appendingPathComponent("test").appendingPathExtension("png") | |
caputreRegion(toURL: url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment