Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# encoding: UTF-8
# merge pages from two pdf documents (same as Merge Every Other)
# only the two documents to be merged must be opened, the first must be the front window.
# this assumes a feed scanner, hence expects the second document's pages to be reversed.
require 'appscript'
include Appscript
#!/usr/bin/env ruby
# encoding: UTF-8
pid = fork and (Process.detach(pid); exit) # Go to background.
require 'appscript'
SRC_MACRUBY_WAIT_FOR_PLAYER_NOTIFICATION = <<-RUBY
framework "Cocoa"
def playerInfo(notification); exit; end
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
require 'pathname'
include Appscript
### Usage:
# ./itunes-mk-playlist.rb \
# ~/"Music/iTunes/iTunes Media/Music/Atomine Elektrine/Zektor X/09 ...and Ever.mp3" \
@kch
kch / gist:1726439
Created February 2, 2012 23:30
Copy the URLs for the selected messages in Mail to the clipboard.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
require 'cgi'
###################################################################
# Copy the URLs for the selected messages in Mail to the clipboard.
###################################################################
@kch
kch / unicode ops.hs
Created October 24, 2011 16:46
unicode operators yay!
#!/usr/bin/env runhaskell
(≤) = (<=)
(≥) = (>=)
(≠) = (/=)
(÷) = (div)
main = do
print (1 ≤ 2)
print (2 ≥ 1)
@kch
kch / target_browser.m
Created January 28, 2011 02:32
Get the path to the frontmost app if it's Safari or Webkit, fallsback to default browser.
// ## compile this with:
// clang \
// -framework Foundation \
// -framework AppKit \
// -framework ApplicationServices \
// -fobjc-gc-only \
// -o target_browser \
// target_browser.m
#import <Foundation/Foundation.h>
@kch
kch / browser.rb
Created January 28, 2011 02:24
browser function used in my appscripts to target Safari or WebKit dynamically
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
VALID_BROWSERS = %w[ WebKit Safari ]
# Used in my appscripts to target Safari or WebKit dynamically.
# Returns an Appscript::Application for one of these browsers following this priority:
# 1. is frontmost
# 2. is running and default
@kch
kch / frontmost-browser.sh
Created January 28, 2011 02:14
Test case for WTF is up with System Events getting the processes for Safari and WebKit
#!/bin/bash
function safari { open -a Safari; }
function webkit { open -a WebKit; }
function reset {
killall Safari 2>/dev/null
killall WebKit 2>/dev/null
}
@kch
kch / mvdn
Created October 19, 2010 21:51
Rename files to all lowercase in two steps, works on a case-insensitive FS like HFS.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'fileutils'
require 'unicode_utils'
ARGV.each do |f|
f_ = UnicodeUtils.downcase(f)
f__ = "#{f_}_#{rand}"
FileUtils.mv(f, f__)
@kch
kch / ipv6.rb
Created October 14, 2010 21:22
QUIZZZZS validate an ip v6
#!/usr/bin/env ruby
# encoding: UTF-8
require 'yaml'
def ipv6?(s)
raise NotImplementedError
end
good, bad = YAML::load(DATA.read).values_at *%w[ GOOD BAD ]
results = []