Skip to content

Instantly share code, notes, and snippets.

@stvhwrd
stvhwrd / sleep-harddrive.md
Last active May 24, 2018 18:53
Sleep all disks on Mac after 1 minute of inactivity

If you've added a second hard drive to your Macbook and are finding that it spins up too often/long (i.e. noisy, eats battery)

Instruct the OS to put all disks to sleep after 1 minute of inactivity:

sudo pmset -a disksleep 1

@stvhwrd
stvhwrd / hide-iterm-dock-icon.md
Last active November 3, 2023 16:18
Hide the iTerm dock icon on Mac OS X

Note: you can now configure this simply in iTerm2's application settings. Go to Preferences > Appearance > System and select "Exclude from Dock and ⌘-Tab Application Switcher".


On my dual-drive MacBook Pro I have remapped the eject key to F13 using Karabiner and NoEjectDelay. The eject key has been assigned as the hotkey for a guake-style visor terminal using iTerm2. Having its own hotkey precludes the need for an icon, so I prefer to hide the iTerm dock icon.

To hide the dock icon of iTerm2 on Mac OS X:

/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/iTerm.app/Contents/Info.plist
@stvhwrd
stvhwrd / sublime-text-CLI-launcher.md
Last active September 13, 2015 16:27
Create a shortcut so we can launch Sublime Text from the command-line, eg. "subl list.txt"

####Create a shortcut so we can launch Sublime Text from the terminal:

ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

Now you can open a file with subl myfile.py

or start a new project in the current directory with subl .

@stvhwrd
stvhwrd / macdown-CLI-launcher.md
Last active March 4, 2019 00:20
Create a shortcut so we can launch MacDown from the command line, eg. "macdown readme.md"

####Create a shortcut so we can launch MacDown from the command line:

ln -s /Applications/MacDown.app/Contents/SharedSupport/bin/macdown /usr/local/bin/macdown

Now you can open a Markdown file with macdown myfile.md

or start a new project in the current directory with macdown .

@stvhwrd
stvhwrd / icon-restore.md
Last active August 29, 2015 14:19
Restore original icons for system folders by deleting custom icon folders (such as those created by MEGA sync) on Mac OS X

####Remove custom icon from folder your_folder:

cd your_folder; rm Icon$'\r'

After executing this command, the operating system should immediately restore the default folder icon.

####Example usage:

@stvhwrd
stvhwrd / launchpad-reset.md
Last active May 10, 2023 21:31
Delete and rebuild LaunchPad on Mac OS X to improve appearance and eliminate obsolete app icons

####First - reset LaunchPad:

defaults write com.apple.dock ResetLaunchPad -bool true; killall Dock

####Second - rebuild the database:

rm ~/Library/Application\ Support/Dock/*.db; killall Dock
@stvhwrd
stvhwrd / combine-pdf.md
Last active March 26, 2023 11:19
Combining PDF files on the command line in OSX

###While this script does concatenate pdf files, I haven't yet figured out in which order it does so. On a sample of 19 pdf files, logically named 01something.pdf, 02something.pdf, 03something.pdf, etc. the order of the merged product seemed almost random...

...from Tiger onwards, OSX ships with a Python script that concatenates pdf files (merges them together). The script is already executable, and Python is pre-installed on OS X, so all you need to do is point it at your pdf files and run

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o PATH/TO/YOUR/MERGED/FILE.pdf /PATH/TO/ORIGINAL/1.pdf /PATH/TO/ANOTHER/2.pdf /PATH/TO/A/WHOLE/DIR/*.pdf

I prefer putting the link in /usr/local/bin, as it is in the $PATH and therefore I can run the command from anywhere. To set up the link, you need to navigate to the directory where you want the link.

@stvhwrd
stvhwrd / website-dl.md
Last active March 13, 2024 17:05
Download an entire website for offline use with wget. Internal inks will be corrected so that the entire downloaded site will work as it did online.

The best way to download a website for offline use, using wget

There are two ways - the first way is just one command run plainly in front of you; the second one runs in the background and in a different instance so you can get out of your ssh session and it will continue.

First make a folder to download the websites to and begin your downloading: (note if downloading www.SOME_WEBSITE.com, you will get a folder like this: /websitedl/www.SOME_WEBSITE.com/)


STEP 1:

# This script prevents Spotify's Auto-updating on OS X (tested on OS X 10.10.3 with Spotify 1.0.3.101.gbfa97dfe)
# Based on this tutorial:
# http://supraliminal.net/blog/2013/4/21/how-to-revert-back-to-the-older-better-spotify-client
#
# This script must be run as root:
# sudo sh doNotUpdateSpotify.sh
#
FILE="/tmp/out.$$"
if [ "$(id -u)" != "0" ]; then
@stvhwrd
stvhwrd / uvicMAC.sh
Last active August 29, 2015 14:20
Set up the UVic iMacs to suit my workflow. [Update: This Gist inspired a new project - Red-Carpet: https://www.github.com/stvhwrd/red-carpet]
#!/bin/bash
# #download dmg
# curl -LOC - http://foo.bar/file.ext
# #mount
# hdiutil mount ~/Chromium_OSX_42.0.2311.152.dmg
# #copy the app