Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@cmittendorf
cmittendorf / LocateMe.swift
Created April 23, 2015 07:32
A command line tool for Mac OS X written in Swift that uses CoreLocation for reverse geocoding a location from latitude and longitude. The geocoding part of this script will work on OS X as well as iOS.
#!/usr/bin/env swift
// Run this command line tool as a dynamic script or compile a binary
// using the following command:
// swiftc -sdk `xcrun --show-sdk-path` LocateMe.swift
import Cocoa
import CoreLocation
extension String {
@cmittendorf
cmittendorf / StartTrackingDocumentIdentifier.swift
Created August 21, 2015 08:44
A script to enable tracking the DocumentIdentifier for a file on OSX.
#!/usr/bin/env swift
import Foundation
let args = Process.arguments
if (args.count != 2) {
print("usage: \(args[0].lastPathComponent) <file>\n")
exit(-1)
}
@cmittendorf
cmittendorf / DocumentIdentifier.swift
Created August 1, 2015 10:51
Returns the NSURLDocumentIdentifierKey for a file.
#!/usr/bin/env swift
import Foundation
let args = Process.arguments
if (args.count != 2) {
print("usage: \(args[0]) <file>\n")
exit(-1)
}
@cmittendorf
cmittendorf / RegisterSettingsBundleDefaults.swift
Created April 19, 2015 20:37
A small extension for registering NSUserDefaults default values using its registerDefaults method from the default values of a settings bundle. See http://oleb.net/blog/2014/02/nsuserdefaults-handling-default-values/ for more information on NSUserDefaults and default values. The code respects an ApplicationGroupContainerIdentifier key and uses N…
import Foundation
if let bundleURL = NSBundle.mainBundle().URLForResource("Settings", withExtension: "bundle") {
NSUserDefaults.registerDefaults(settingsBundleURL: bundleURL)
}
extension NSUserDefaults {
static func registerDefaults(#settingsBundleURL: NSURL) {
if let rootDict = NSDictionary(contentsOfURL: settingsBundleURL.URLByAppendingPathComponent("Root.plist")) {
var defaults: NSUserDefaults?
@cmittendorf
cmittendorf / add_safari_url_to_omni_outliner.applescript
Last active February 27, 2018 14:01
An AppleScript for adding the URL from the current tab to an OmniOutliner document.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set document_name to "Safari Links"
set row_topic to "Links"
set browser_url to missing value
tell application "Safari"
set browser_url to URL of first document
@cmittendorf
cmittendorf / iTunes2Elastic.js
Created September 15, 2014 21:06
A little script for exporting you iTunes library into an ElasticSearch database with an index named 'itunes' (requires Yosemite). You may then search for all your Beatles songs using the following command: curl --silent -XGET "localhost:9200/itunes/_search?pretty&size=10000" -d '{"query":{"match":{"artist":"beatles"}}}'|jq '[.hits.hits[]._source]'
var app = Application.currentApplication()
app.includeStandardAdditions = true
var itunes = Application("iTunes")
var url = "http://localhost:9200/itunes/track/"
var lib = itunes.sources["Library"]
var tracks = lib.tracks()
@cmittendorf
cmittendorf / copyLocationFromFile.sh
Created May 13, 2017 10:12
Copies the location information on macOS from one file to another.
#!/usr/bin/env bash
if [ $# != 2 ]; then
echo `basename $0`" <src file> <dst file>"
exit
fi
xattr -w "com.apple.metadata:kMDItemLatitude" $(mdls -name kMDItemLatitude "$1" | awk '{print $3}' | sed s/\"//g) "$2"
xattr -w "com.apple.metadata:kMDItemLongitude" $(mdls -name kMDItemLongitude "$1" | awk '{print $3}' | sed s/\"//g) "$2"
@cmittendorf
cmittendorf / copyCreatedDateFromFile.sh
Created May 13, 2017 08:18
A script for macOS which copies the created date from one file to another.
#!/usr/bin/env bash
if [ $# != 2 ]; then
echo `basename $0`" <src file> <dst file>"
exit
fi
SetFile -d '$(GetFileInfo -m "$1")' "$2"
@cmittendorf
cmittendorf / ViewTextOfSafariInPages.scpt
Created January 10, 2017 07:51
Creates a new Pages document from the text of the frontmost Safari document.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set content to missing value
tell application "Safari"
try
set content to text of first document
end try
end tell
@cmittendorf
cmittendorf / ServiceLocator.swift
Last active July 13, 2016 12:45
A simple ServiceLocator written in Swift.
protocol ServiceLocatorType {
func getService<T>(type: T.Type) -> T
}
public final class ServiceLocator: ServiceLocatorType {
public static let instance = ServiceLocator()
private var serviceRegistry: [String:Any] = [:]