Skip to content

Instantly share code, notes, and snippets.

View OskarGroth's full-sized avatar

Oskar Groth OskarGroth

View GitHub Profile
@kirb
kirb / Device.swift
Last active January 2, 2024 04:18
Get Mac device image based on device class - https://kirb.me/2023/04/15/mac-device-icon-by-device-class.html
import Cocoa
import UniformTypeIdentifiers
extension UTTagClass {
static let deviceModelCode = UTTagClass(rawValue: "com.apple.device-model-code")
}
extension UTType {
static let macBook = UTType("com.apple.mac.laptop")
static let macBookWithNotch = UTType("com.apple.mac.notched-laptop")
@GreyAsteroid
GreyAsteroid / StageManagerOptions.md
Last active September 30, 2024 01:17
Stage Manager Options

defaults write com.apple.WindowManager GloballyEnabled -bool [True/False] Adjusts whether Stage Manager is enabled or not.

defaults write com.apple.WindowManager AutoHide -bool [True/False] Adjusts auto hide behavior. This option controls the "Show Recent Apps" and "Hide Recent Apps" GUI option.

defaults write com.apple.WindowManager AutoHideOverlapThreshold -int [-2147483647...2147483647] Unsure what this option does. Should be noted that when AutoHide is set to False and this option is set to -17 or lower Stage Manager behaves as if AutoHide is set to True.

defaults write com.apple.WindowManager LeftStripMaximumRowCount -int [-2147483647...2147483647]

@sharplet
sharplet / AnyEventPublisher.swift
Last active February 17, 2024 02:18
PublisherQueue — Serialise the execution of multiple publishers like OperationQueue
import Combine
public enum AnyError: Error {
case never(Never)
case failure(Error)
}
public enum AnyEvent {
case output(Any)
case completion(Subscribers.Completion<AnyError>)
//
// ContentView.swift
// ComposableTest
//
import ComposableArchitecture
import SwiftUI
struct ContentView: View {
var store: Store<Main.State, Main.Action>
@izakpavel
izakpavel / AnimatablePairWithAnimatableVector.swift
Last active February 11, 2022 16:28
Mixing custom AnimatableVector in AnimatablePair
//
// Mixing custom AnimatableVector in AnimatablePair
//
// Created by Pavel Zak on 26/05/2020.
// Copyright © 2020 Pavel Zak. All rights reserved.
//
import SwiftUI
struct AnimatableVector2D: VectorArithmetic {
@frankfka
frankfka / iOSCustomSegmentedControlSwiftUI.swift
Created May 17, 2020 16:47
Custom Segmented Picker / Segmented Control in SwiftUI
import SwiftUI
extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
@danielpunkass
danielpunkass / RSDimensionHuggingTextField.swift
Last active May 30, 2024 01:08
NSTextField subclasses that grow/shrink their width or height to fit text content
//
// RSDimensionHuggingTextField.swift
// RSUIKit
//
// Created by Daniel Jalkut on 6/13/18.
//
import Cocoa
// You probably want to use one of RSHeightHuggingTextField or RSWidthHuggingTextField, below
@fabiogiolito
fabiogiolito / FacebookReactions.swift
Last active August 11, 2022 15:25
Recreating Facebook Reactions with SwiftUI. Demo Video: https://twitter.com/fabiogiolito/status/1142226669471748096
//
// FacebookReactions.swift
//
// Created by Fabio Giolito on 10/06/2019.
// Follow me: https://twitter.com/fabiogiolito
//
import SwiftUI
struct FacebookReactions : View {
@avaidyam
avaidyam / animate_dark.swift
Last active February 11, 2022 14:20
Animated dark mode transition
// swiftc this file & mv to /usr/local/bin
import Cocoa
typealias NSGlobalPreferenceTransitionBlock = @convention(block) () -> Void
@objc protocol NSGlobalPreferenceTransitionProtocol: NSObjectProtocol {
static func transition() -> AnyObject
func waitForTransitionWithCompletionHandler(_ arg1: @escaping NSGlobalPreferenceTransitionBlock)
func postChangeNotification(_ arg1: UInt64, completionHandler arg2: @escaping NSGlobalPreferenceTransitionBlock)
}
let NSGlobalPreferenceTransition: AnyClass = NSClassFromString("NSGlobalPreferenceTransition")!
@ole
ole / Mojave-dynamic-wallpaper-notes.md
Last active November 3, 2024 20:05
Reverse-engineering the dynamic wallpaper file format in macOS Mojave.

The dynamic wallpaper in MacOS Mojave is a single 114 MB .heic file that seems to contain 16 embedded images.

It also contains the following binary plist data in its metadata under the key "Solar". It's an array of 16 items, each with four keys:

  • i (integer). This seems to be the image index.
  • o (integer). This is always 1 or 0. Stephen Radford thinks it indicates dark mode (0) vs. light mode (1).
  • a (decimal). I’m pretty sure this is the angle of the sun over the horizon. 0º = sunset/sunrise. 90º = sun directly overhead. Negative values = sun below horizon.
  • z (decimal). This seems to be the cardinal position of the sun relative to the camera. 0º = sun is directly in front of the camera. 90º = sun is directly to the right of the camera. 180º = sun is directly behind the camera.