Sometimes you need to take a quick selfie while you're working, and get it on the clipboard (er, pasteboard). With a single command, you can take a selfie and:
- paste it into Slack to annoy your coworkers
- send it to your significant other via iMessage
- or just simply record your expressions of horror while computering.
Use homebrew to install imagesnap
, which will allow you to quickly snap an image using your built-in camera:
brew install imagesnap
Next you'll need to build a tool that allows you to copy images to the clipboard from the command line (the pbcopy
command doesn't support this). Luckily, Alec Jacobson has written such a tool, and it's super easy to build. I've mirrored the code for you here; simply download the file impbcopy.m
below, and run the following to compile it:
gcc -Wall -g -O3 -ObjC -framework Foundation -framework AppKit -o impbcopy impbcopy.m
You'll need to move the resulting impbcopy
binary to somewhere within your PATH
. I'll let you figure that out.
Final step is adding a quick function to your .bash_profile
to take the photo, archive it (optionally), and copy it to the clipboard.
# directory in which to amass collection of selfies
export SELFIE_ARCHIVE_PATH="$HOME/selfies"
# function to actually take a selfie
selfie(){
mkdir -p $SELFIE_ARCHIVE_PATH
local filepath="$SELFIE_ARCHIVE_PATH/$(date +%y%m%d%H%M%S).png"
imagesnap $filepath -w 1.0 # the -w flag gives the camera time to warm up
impbcopy $filepath
}
Once you've reloaded your .bash_profile
, simply run
selfie
and you'll have a selfie waiting for you on the clipboard, and archived for later use!