Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@cmittendorf
cmittendorf / terminal-size.sh
Last active August 29, 2015 13:59
Set the size of the current terminal to number of columns and rows.
#!/usr/bin/env bash
if [ $# != 0 -a $# != 2 ]; then
echo `basename $0`" <cols> <rows>"
exit
fi
COLS=${1:-80}
ROWS=${2:-25}
@cmittendorf
cmittendorf / ArrayExtension.swift
Last active August 29, 2015 14:02
Adds an each closure to Arrays in Swift.
#!/usr/bin/env xcrun swift -i
extension Array {
func each(closure:(T) -> ()) {
for item:T in self {
closure(item)
}
}
func eachWithIndex(closure:(Int, T) -> ()) {
var i:Int = 0
@cmittendorf
cmittendorf / View WWDC 2014 Videos with QT7.scpt
Last active August 29, 2015 14:02
This AppleScript will allow you to select a WWDC 2014 video and open it automatically using the QuickTime 7 player (http://support.apple.com/kb/DL923) allowing you to increase the playback speed as mentioned in BitsUndSo episode #379 (http://www.bitsundso.de/bus379/). Be aware that the script does not check if the QT7 player is already installed.
(***
Use this AppleScript to launch WWDC 2014 videos in QuickTime Player 7, where
you can adjust the playback speed to your needs (⌘ + k). Have fun!
Christian Mittendorf, 15.06.2014
cmittendorf<et>me.com
***)
set page_url to "https://developer.apple.com/videos/wwdc/2014/"
set videos to missing value
@cmittendorf
cmittendorf / safari-text.sh
Created June 20, 2014 07:08
Retrieve the text content of the current web page from Safari
#!/usr/bin/env bash
# prepared for Yosemite (10.10)
# osascript -l JavaScript -e "Application('Safari').documents()[0].text()"
CONTENT=$(osascript -ss << EOF
tell application "Safari"
tell its first document
get its text
end tell
@cmittendorf
cmittendorf / safari-url.sh
Created June 20, 2014 07:10
Get the URL of the current web page from Safari
#!/usr/bin/env bash
URL=$(osascript << EOF
tell application "Safari"
tell its first document
URL
end tell
end tell
EOF)
@cmittendorf
cmittendorf / MakeNewFileOrFolder.applescript
Last active August 29, 2015 14:04
Create new files or folders with a keystroke and by using the Tool FastScripts (http://www.red-sweater.com/fastscripts/) you can overwrite the default Finder Shift-Command-N shortcut to create a new folder for invoking our new script.
(**
Create new files or folders with a keystroke and by using the Tool
FastScripts http://www.red-sweater.com/fastscripts/
you can overwrite the default Finder Shift-Command-N shortcut
to create a new folder for invoking our new script.
**)
tell application "Finder"
-- default name for a new file following
-- the Finders convention for naming folders
set newFileName to "untitled file"
@cmittendorf
cmittendorf / display-notification.sh
Last active August 29, 2015 14:04
A little snippet showing how to create a log function in bash that displays its log message in the Mac OS X notification center as well as on the console.
#!/usr/bin/env bash
function log()
{
echo `date +"[%d.%m.%Y %H:%M:%S] "`$1
# Available Sounds:
# Basso, Blow, Bottle, Frog, Funk, Glass, Hero,
# Morse, Ping, Pop, Purr, Sosumi, Submarine, Tink
osascript << EOF
@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 / 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()
}