Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@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 / 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] = [:]
@cmittendorf
cmittendorf / Platform.swift
Created June 24, 2016 08:32
Test in your iOS app, if your app is running in the Simulator.
import Foundation
struct Platform {
/// Check if the current platform is the simulator.
///
/// - Returns: true if the current platform is the simulator
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true
@cmittendorf
cmittendorf / CGFloatToRadians.swift
Created June 12, 2016 08:19
Extend CGFloat to calculate the radians from its value.
extension CGFloat {
var radians: CGFloat {
let degree = Double(self)
return CGFloat(degree * M_PI / 180.0)
}
}
@cmittendorf
cmittendorf / Open AWS Servers with SSH.applescript
Created November 11, 2015 10:27
Open all AWS EC2 instances of a specific server group using csshX from the current AWS console page in Safari.
set serversList to {}
set serverGroups to {"MyGroup1", "MyGroup2", "MyGroup3"}
set alertTitle to "Open AWS Servers with SSH"
on openServers(servers)
set csshx to "/usr/local/bin/csshX -y 4 --slave_settings_set CSSHX --ssh_args \"-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null\" "
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set command to (csshx & servers as text) & " &"
get do shell script command
@cmittendorf
cmittendorf / sshToAWSServer.AppleScript
Last active September 17, 2015 22:16
An AppleScript to ssh with Terminal.app into the the currently selected server instance in the EC2 Management Console in Safari.app.
set aws to missing value
tell application "Safari"
tell current tab
set aws to do JavaScript "document.getElementsByClassName(\"AOB\")[0].textContent.match(/DNS: (.*\\.amazonaws\\.com)/)[1]"
end tell
end tell
if aws is not missing value then
tell application "Terminal"
@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)
}