Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@cmittendorf
cmittendorf / CodeSign Information.applescript
Last active August 29, 2015 14:04
Show codesign information for an application. You may download a signed (of course) version here: http://h1152756.serverkompetenz.net/SharedStuff/Show%20CodeSign%20Information.zip
on open theFiles
repeat with aFile in theFiles
set appPath to POSIX path of aFile
set codeSignInformation to do shell script "codesign -vd '" & appPath & "' 2>&1"
display dialog codeSignInformation with title ("codesign -vd " & appPath) buttons {"Ok"} default button 1
end repeat
end open
on run
open (choose file with multiple selections allowed)
@cmittendorf
cmittendorf / OpenTerminalWithPath.applescript
Created August 31, 2014 10:37
Open a Terminal window with the front Finder window as path.
on run
tell application "Finder"
activate
try
set this_folder to (the target of the front window) as alias
on error
set this_folder to startup disk
end try
my open_terminal_window(this_folder)
end tell
@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 / OpenSafariSourceInBBEdit.js
Created October 18, 2014 11:30
open Safari HTML source in BBEdit using new Yosemite JavaScript automation
var Safari = Application ("Safari")
if (Safari.documents().length > 0) {
var source = Safari.documents()[0].source()
Application("BBEdit").Document({"contents":source, "source language":"HTML"}).make()
}
@cmittendorf
cmittendorf / AppleScriptProgressbar.applescript
Created October 26, 2014 09:25
As a new feature of OS X Yosemite, you now can display a progress bar from your AppleScript.
set progress total steps to 100
repeat with i from 1 to 100
set progress description to "Item " & i & " of " & 100
set progress additional description to "foobar"
delay 1
set progress completed steps to i
end repeat
@cmittendorf
cmittendorf / ScriptProgressYosemite.js
Created October 26, 2014 09:44
If you want to use the new JavaScript for automation on Yosemite, you can display a scripts progress using a scripts Progress object.
Progress.totalUnitCount = 100
Progress.completedUnitCount = 0
Progress.description = "Testing progress"
Progress.additionalDescription = "foobar"
for(i = 0; i < Progress.totalUnitCount; i++) {
Progress.description = "Item " + i + " of " + Progress.totalUnitCount
delay(1)
Progress.completedUnitCount = i
}
@cmittendorf
cmittendorf / open_urls_in_string.rb
Last active August 29, 2015 14:09
A Ruby Automator action for opening all URLs and JIRA ticket ids from the input string.
require 'uri'
# without force_encoding ruby will throw an
# "invalid byte sequence in US-ASCII" exception
# when running this script from Automator
input = ARGF.read.force_encoding("UTF-8")
# scan for JIRA Ticket IDs like MYPROJECT-42
input.scan(/([A-Z]+\-[0-9]+)/).each do |id|
url = "https://<your JIRA server>/browse/#{id[0]}"
@cmittendorf
cmittendorf / rename_git_tags.rb
Created December 19, 2014 11:42
Renames already pushed git tags to follow a folder structure staging/<version> or master/<version>.
#!/usr/bin/env ruby
#
# renames git tags
# 3.7.0.31-staging -> staging/3.7.0.31
# 3.7.0 -> master/3.7.0
#
# see http://blog.sidmitra.com/how-to-rename-a-tag-already-pushed-to-a-remot
#
# make sure that other repo users call
# pull --prune --tags
@cmittendorf
cmittendorf / trace_all_mysql_queries.d
Created February 26, 2015 18:11
A dtrace script for tracing all SQL queries a mysql server is executing. Call this script using `sudo ./trace_all_queries.d -p `pgrep mysqld`.
#!/usr/sbin/dtrace -s
#pragma D option quiet
pid$target:mysqld:*mysql_parse*:entry
{
printf("[%Y] %s\n", walltimestamp, copyinstr(arg1));
}
@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?