Skip to content

Instantly share code, notes, and snippets.

@GeekAndDad
GeekAndDad / RemindersListToTextEdit.scpt
Last active September 25, 2020 19:02
Hacked together AppleScript to get a list from Reminders and make a new TextEdit document with the items in the list suitable for printing.
tell application "Reminders"
set listNames to {}
repeat with aList in lists
copy name of aList to end of listNames
end repeat
set listName to choose from list listNames with prompt "Select the list to print:"
-- now find list object for the choosen list
set listToPrint to ""
repeat with aList in lists
@GeekAndDad
GeekAndDad / ContentView.Swift
Created April 3, 2020 23:20
Bug? Two `.alert` modifiers mean only last one works?
//
// ContentView.swift
// TestAlert
//
//
import SwiftUI
struct ContentView: View {
@State private var showAlert1: Bool = false
@GeekAndDad
GeekAndDad / detweet.swift
Created June 21, 2020 04:02 — forked from mxcl/detweet.swift
Delete all tweets and favorites older than two months ago. Instructions in comment.
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@GeekAndDad
GeekAndDad / confusing.swift
Last active July 24, 2020 03:49
Computed properties don't call specialized version of functions? Work fine when you call the specialized functions directly but not when those functions are used within a getter or setter it seems… ???
// macOS playground source
// swift 5.3, Xcode 12b2
import Cocoa
struct Foo<A> {
var subVal: Any?
let defaultValue: A
init(defaultValue: A) {
@GeekAndDad
GeekAndDad / TestDecodingFunTests.swift
Last active September 22, 2020 10:13
@chunkyguy on twitter said they were facing a similar challenge to one I was facing, but their challenge actually seemed a little different and potentially easier. So I explored their challenge and created this solution.
//
// TestDecodingFunTests.swift
// TestDecodingFunTests
//
// Created by Dad on 9/22/20.
//
// Poster wanted to be able to parse (visual) "components" out of a json file that would
// have various components of various types.
@GeekAndDad
GeekAndDad / Move Safari Windows UP.scpt
Last active November 18, 2021 05:15
Code for a blog post about a silly AppleScript to move Safari windows back up after a bug in Safari moves them down on wake from sleep sometimes. The post is here: https://geekanddad.wordpress.com/?p=2161. This script moves all Safari windows up the same amount to keep their relative positioning and moves them up as much as possible while still …
-- Put in the public domain with zero warranty of any kind
--
-- only tested on macOS 11.6, with Safari 13.0; ymmv
use scripting additions
tell application "Safari"
set windlist to windows
log "Examining " & length of windlist & " windows..."
@GeekAndDad
GeekAndDad / EjectDrives.scpt
Last active December 3, 2024 12:10
AppleScript to eject mounted local disks. Written for when I'm going to take my laptop off my desk and am disconnecting from my TB hub.
-- AppleScript I wrote to eject mounted USB disks before I disconnect my USB-C hub.
-- Notes:
-- this will halt a time machine backup to a locally mounted
-- drive when it tries to eject it.
-- will also halt a time machine backup to a network destination.
-- tested in macOS 11.6 (2021.11.19)
-- License: MIT
tell application "System Events"
set ds to get disks
// Advanced SwiftUI Transitions
// https://swiftui-lab.com
// https://swiftui-lab.com/advanced-transitions
import SwiftUI
struct GeometryEffectTransitionsDemo: View {
@State private var show = false
var body: some View {
@GeekAndDad
GeekAndDad / ParseTest.swift
Last active January 27, 2022 14:03
Playground to test parsing. Is there simpler way to do this?
import Parsing
/// simple test.
/// First char must exist and must be a char from a to z
/// Followed by zero or more characters from a to z or 0 to 9
/// Must end with a space or be the end of input
///
let validFirstChars = CharacterSet(charactersIn: "a"..."z")
let validFollowingChars = CharacterSet(charactersIn: "0"..."9").union(validFirstChars)
@GeekAndDad
GeekAndDad / macOSplayground.swift
Created March 12, 2022 18:38
Simple test around throwing close function and api design
enum ConnectionError: Error {
case fakeWork
case close
case connect
}
struct Connection {
func close(fail: Bool = false) throws {
if fail {
print("throwing during close connection ")