Skip to content

Instantly share code, notes, and snippets.

@yoterpa
Created November 22, 2015 08:18
Show Gist options
  • Save yoterpa/b4102b26f0237651f8d8 to your computer and use it in GitHub Desktop.
Save yoterpa/b4102b26f0237651f8d8 to your computer and use it in GitHub Desktop.

App Icons

Create App Icon

Function to quickly create an application icon from 1024px master file.

function mkicns() {
    if [[ -z "$@" ]]; then
        echo "Input file missing"
    else
        filename=${1%.*}
        mkdir $filename.iconset
        sips -z 16 16   $1 --out $filename.iconset/icon_16x16.png
        sips -z 32 32   $1 --out $filename.iconset/[email protected]
        sips -z 32 32   $1 --out $filename.iconset/icon_32x32.png
        sips -z 64 64   $1 --out $filename.iconset/[email protected]
        sips -z 128 128 $1 --out $filename.iconset/icon_128x128.png
        sips -z 256 256 $1 --out $filename.iconset/[email protected]
        sips -z 256 256 $1 --out $filename.iconset/icon_256x256.png
        sips -z 512 512 $1 --out $filename.iconset/[email protected]
        sips -z 512 512 $1 --out $filename.iconset/icon_512x512.png
        cp $1 $filename.iconset/[email protected]
        iconutil -c icns $filename.iconset
        rm -r $filename.iconset
    fi
}

Disk Images

Create Disk Image From Folder Contents

hdiutil create -volname "Volume Name" -srcfolder /path/to/folder -ov diskimage.dmg

If you'd like to encrypt the disk image:

hdiutil create -encryption -stdinpass -volname "Volume Name" -srcfolder /path/to/folder -ov encrypted.dmg

By default, you'll be prompted for a password. You can automate that by piping in a password:

echo -n YourPassword | hdiutil create -encryption -stdinpass -volname "Volume Name" -srcfolder /path/to/folder -ov encrypted.dmg

Convert File to HTML

Supported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).

textutil -convert html file.ext

Change Working Directory to Finder Path

If multiple windows are open, it chooses the top-most one.

cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"

Open Current Folder

open .

Prevent System Sleep

Prevent sleep for 1 hour:

caffeinate -u -t 3600

Convert Audio File to iPhone Ringtone

afconvert input.mp3 ringtone.m4r -f m4af

Speak Text with System Default Voice

say 'All your base are belong to us!'

Auto-Play Videos in QuickTime Player

defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1

TCP/IP

Show Application Using a Certain Port

This outputs all applications currently using port 80.

sudo lsof -i :80

Show External IP Address

dig +short myip.opendns.com @resolver1.opendns.com

Show Wi-Fi Network Passwords

Exchange SSID with the SSID of the access point you wish to query the password from.

security find-generic-password -D "AirPort network password" -a "SSID" -gw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment