Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefan stefanschmidt

View GitHub Profile
@stefanschmidt
stefanschmidt / disable-finder.sh
Created Jul 30, 2014
Temporarily disable Finder on OS X
View disable-finder.sh
# disable Finder until re-login/restart
launchctl unload /System/Library/LaunchAgents/com.apple.Finder.plist
# re-enable Finder without re-login/restart
launchctl load /System/Library/LaunchAgents/com.apple.Finder.plist
launchctl start com.apple.Finder
@stefanschmidt
stefanschmidt / disk-usage.sh
Last active Aug 29, 2015
Human readable and ascendingly sorted disk usage
View disk-usage.sh
# files/folders in current directory
du -sh * | sort -rh
# interactive du with visualization
ncdu
@stefanschmidt
stefanschmidt / disable-spotlight-volume.sh
Last active Aug 29, 2015
Disable Spotlight indexing for a volume
View disable-spotlight-volume.sh
# disable Spotlight indexing for a volume
touch /Volumes/Foobar/.metadata_never_index
# verify indexing status of that volume
mdutil -i on /Volumes/Foobar
@stefanschmidt
stefanschmidt / disable-hires-text-icon.sh
Last active Aug 29, 2015
Disable high-resolution preview icons of plain text files in OS X Finder
View disable-hires-text-icon.sh
# show which user/application generator handles plain text files (e.g. TextMateQL.qlgenerator)
qlmanage -m | grep public.plain-text
# disable the generator (at least until the next application update)
cd /Applications/TextMate.app/Contents/Library/QuickLook
mv TextMateQL.qlgenerator TextMateQL.qlgenerator.disabled
# reset quicklookd and relaunch Finder
qlmanage -r
killall Finder
@stefanschmidt
stefanschmidt / create-bootable-usb-mavericks.sh
Created Nov 21, 2014
Create a bootable USB drive with OS X Mavericks installer
View create-bootable-usb-mavericks.sh
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/USB_Drive --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
@stefanschmidt
stefanschmidt / scrape-wp-images.sh
Last active Aug 29, 2015
Scrape images of postings by category from a Wordpress blog
View scrape-wp-images.sh
#!/bin/bash
# depends on cli-scrape (https://github.com/pthrasher/cli-scrape)
# and GNU Parallel (available via Homebrew)
for i in `seq 1 100`;
do
scrape http://foo.com/category/bar/page/$i/ '//img/@src' |
sed -En 's/(.*\.)(jpg|png|gif).*/\1\2/p' |
parallel --jobs 10 wget {}
done
View sort-img-by-size.sh
#!/bin/bash
# depends on ImageMagick (available via Homebrew)
for image in ls *.{jpg,png,gif};
do res=$(identify -format %wx%h\\n $image);
mkdir -p $res;
mv $image $res;
done
@stefanschmidt
stefanschmidt / scale-pdf-page-size.sh
Last active Aug 29, 2015
Scale PDF page size without rasterizing
View scale-pdf-page-size.sh
# depends on cpdf (http://community.coherentpdf.com)
# scale with factor relative to original size
cpdf -scale-page "0.5 0.5" in.pdf -o out.pdf
# scale to fixed size without changing the aspect ratio
cpdf -scale-to-fit a4portrait in.pdf -o out.pdf
@stefanschmidt
stefanschmidt / black-pdf.sh
Last active Aug 29, 2015
Convert all text in PDF to black without rasterizing
View black-pdf.sh
# depends on cpdf (http://community.coherentpdf.com)
cpdf -blacktext in.pdf -o out.pdf
@stefanschmidt
stefanschmidt / repair-pdf.sh
Last active Aug 29, 2015
Repair Calibre PDFs for OS X Preview
View repair-pdf.sh
# Make PDFs generated by Calibre work properly in OS X Preview
# http://www.mobileread.com/forums/showthread.php?t=220576
# depends on GhostScript (available via Homebrew)
gs -o out.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress in.pdf