Skip to content

Instantly share code, notes, and snippets.

View edenwaith's full-sized avatar

Chad Armstrong edenwaith

View GitHub Profile
@edenwaith
edenwaith / erasefreespace.m
Created October 6, 2017 03:43
Example code for erasing free disk space by calling diskutil from an NSTask
/*
* erasefreespace.m
* Description: Parse a string for the percentage of freespace erased
* Author: Chad Armstrong
* Date: 3 October 2017
* To compile: gcc -framework Foundation erasefreespace.m -o erasefreespace
*/
#import <Foundation/Foundation.h>
@edenwaith
edenwaith / batch_compress_tiffs
Created September 13, 2017 22:57
Compress a bunch of TIFF images using the LZW compression method and sips from the Mac command line
ls *.tif | xargs sips -s format tiff -s formatOptions lzw
var s_ajaxListener = new Object();
s_ajaxListener.tempOpen = XMLHttpRequest.prototype.open;
s_ajaxListener.tempSend = XMLHttpRequest.prototype.send;
s_ajaxListener.callback = function () {
window.location='mpAjaxHandler://' + this.url;
};
XMLHttpRequest.prototype.open = function(a,b) {
if (!a) var a='';
if (!b) var b='';
import objc, os
from Foundation import *
from AppKit import *
ACScriptSuperMenuTitle = None
ACScriptMenuTitle = "Compress with TinyPNG"
ACShortcutKey = 'i'
ACShortcutMask = "command control"
ACIsAction = True
#!/bin/sh
VER1=2.6.33.2
VER2=2.6.38
OSVERSION=`sw_vers -productVersion`
echo "Current OS Version: $OSVERSION"
echo "Arg 2 : $# $0 $1 $2"
if [[ $VER1 > $VER2 ]]; then
@edenwaith
edenwaith / freesize.m
Last active February 1, 2025 03:42
A variety of methods to calculate the free space on a Mac volume
/*
* freesize.m
* Description: Multiple ways to calculate the free space on the root volume
* Blog post: http://www.edenwaith.com/blog/index.php?p=67
* Author: Chad Armstrong
* Date: 6 - 10 May 2017, 25 August 2021
* To compile: gcc -framework Foundation freesize.m -o freesize
* To run: ./freesize
*/
@edenwaith
edenwaith / erase_freespace.sh
Last active June 9, 2017 19:15
Shell script to erase free space on a Mac (Currently a work in progress)
#!/bin/sh
# Erase freespace from the command line: diskutil secureErase freespace [level] [device]
if [ "$#" -lt 1 ]; then
echo "$0: too few arguments"
echo "Usage: $0 path/to/disk" >&2 # echo error to stderr
exit 1
fi
@edenwaith
edenwaith / tss.sh
Last active October 1, 2018 04:15
Command line bash script to take a screenshot of the Xcode Simulator
#!/bin/sh
# TSS = Take Simulator Screenshot
# Script workaround for the crash in Xcode 8 Simulator crashing when
# trying to save a screenshot in El Capitan
# Version: 1.2 (3 February 2017) - Add screenshot to clipboard
# Version: 1.1 (31 January 2017) - Play screenshot file
# Version: 1.0 (Early January 2017) - Initial version
# Change to the Desktop, take the screenshot, then move back to the original directory
@edenwaith
edenwaith / local.updateticketsreminder.plist
Last active July 7, 2019 11:57
Launch Agent plist file to send a macOS notification reminder each evening during the weekdays.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.updateticketsreminder</string>
<key>ProgramArguments</key>
<array>
<!-- osascript -e 'display notification "Update your tickets" with title "Reminder" sound name "Sosumi"' -->
<string>/usr/bin/osascript</string>
@edenwaith
edenwaith / CountOpenSafariTabs.scpt
Last active October 25, 2024 16:32
AppleScript: Count the number of open tabs in Safari
-- CountOpenSafariTabs.scpt
-- Author: Chad Armstrong
-- Date: 13 May 2016
-- Description: Count the number of open tabs in Safari
-- To run from CLI: osascript CountOpenSafariTabs.scpt
tell application "Safari"
--Variables
set winlist to every window