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
// Some Swift code for different ways to find the current username on macOS. | |
// | |
// You can run this in a Playground, or compile it with `swiftc`. Compiling | |
// it will let you experiment with different ways of running the command. | |
print("********** Foundation Usernames **********") | |
// If you are only importing Foundation you have a few options to get the current user. | |
// Note that if run from the CLI they will report the CLI user running them. | |
import Foundation |
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
import Foundation | |
// ProcessInfo is a class that provides information about the current process. | |
// It provides an easy way to access information about the process, the system, and the user. | |
// Note that `processInfo` is a static property on the `ProcessInfo` class. | |
let info = ProcessInfo.processInfo | |
print("Process Info:") | |
print("Process Name: \(info.processName)") |
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
import Foundation | |
// A playground to see different ways to get environment variables in Swift | |
// Foundation is the easiest way using the awesome ProcessInfo class. | |
// Get all of the environment variables for your running process in a Dictionary. | |
let foundationEnv = ProcessInfo().environment | |
print("********** ProcessInfo Environment **********") |
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
// Get crazy and hook MobileGestalt in a Swift Playground! | |
// | |
// If you are a LONG time Mac developer you know that the Gestalt system | |
// used to be a way to get info about your Mac. These days it's a private | |
// thing that Apple locks away and you shouldn't really touch. Most of the info | |
// that you need can probaby be found in IOKit, but some values, like | |
// the provisioningUDID are not avaliable any other way. | |
// | |
// That said, it's a fun exersize to see how to do some various things in Swift. | |
// Things like loading a dylib or calling private C functions. |
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
// This playground shows you a few different ways to get device info via IOKit. | |
// If you want to explore IOKit and look for interesting data I would download | |
// the Additional Developer Tools from Apple and use the IORegistryExplorer app. | |
// It makes it super easy to poke around in the IOKit planes. | |
import IOKit | |
import Foundation | |
// For convient access we can make a computed getter for the PlatformExpert. | |
// Traditionally this has been where you go to find all sorts of data about the |
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
import Foundation | |
extension TimeInterval { | |
var seconds: TimeInterval { self } | |
var minutes: TimeInterval { self * 60 } | |
var hours: TimeInterval { self * 3_600 } | |
var days: TimeInterval { self * 86_400 } | |
var weeks: TimeInterval { self * 604_800 } | |
var months: TimeInterval { self * 2_628_000 } | |
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
// | |
// Activity.swift | |
// | |
// Created by Zachary Waldowski on 8/21/16. | |
// Copyright © 2016 Zachary Waldowski. Licensed under MIT. | |
// | |
import os.activity | |
private final class LegacyActivityContext { |
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
import Cocoa | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
var isScreenLocked: Bool { | |
guard let wssProperties = CGSessionCopyCurrentDictionary() as? [String : Any], (wssProperties["CGSSessionScreenIsLocked"] != nil) else { | |
return false | |
} | |
return true |
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
import Cocoa | |
// Security Session | |
// | |
// You can access bits about the security session to get some basic info. You can only get info about your own session. | |
// Other than the session id, the values are all Bools. | |
var sessionID = SecuritySessionId() | |
var sessionAttrs = SessionAttributeBits() | |
let result = SessionGetInfo(callerSecuritySession, |
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
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
// Simple class to search for things with `NSMetadataQuery`. | |
class Searcher { | |
// This is just for timing things | |
let startTime = Date() | |
NewerOlder