Posts tagged OS X
How to use mdfind to search for every file on OS X
Spotlight is great, but it has some mom-friendly rules that limit the results. Since I’m a power user, I typically want to search the entire computer and see all results. Therefore, I use the mdfind
command to search OS X.
Just pop open Terminal
and type:
mdfind "income tax"
This will search for all files with the metadata words “income tax.”
How to bind Vagrant to port 80 on OS X
First, stop Apache. Apache listens on port 80. If it’s running, Vagrant won’t be able to bind a VM to listen on port 80.
Then, just add a forwarded port to your Vagrantfile
:
config.vm.network "forwarded_port", guest: 80, host: 80
And boot up Vagrant as sudo
:
sudo vagrant up
How to figure out which processes is listening on a port on OS X
sudo lsof -n -i4TCP:$PORT | grep LISTEN
- Replace
$PORT
with the port you are looking for - This only works with TCP ports.
- Prefixing with
sudo
will show proceses the current user does not own
How to start and stop Apache in OS X
How to start Apache:
sudo apachectl start
How to stop Apache:
sudo apachectl stop
How to restart Apache:
sudo apachectl restart
N.B. I am on OS X Mavericks. It ships with Apache 2.
How to run Javascript code on Mac OS X
When developing Javascript, you may wish to run code outside the browser. Luckily OS X comes with a world-class Javascript engine, which features a command-line interpreter.
Since it’s hidden deep inside a framework, create a symbolic link:
sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc /usr/local/bin/js
Now, you can enter the interpreter by simply typing:
js
The interpreter can be quit by typing quit();
or ctrl+c
.
Where is Finder.app located on OS X?
/System/Library/CoreServices/Finder.app
How to start and stop MySQL on OS X
To start MySQL on OS X:
mysql.server start
To stop MySQL on OS X:
mysql.server stop
How to check if Bash is vulnerable to Heartbleed
Run this line in your Bash console:
env x='() { :;}; echo vulnerable' bash -c "only this line should appear"
If you see this, your Bash is vulnerable to Heartbleed:
vulnerable
only this line should appear
If you see this, your Bash is secure from Heartbleed:
only this line should appear
Get Safari's Reading List programmatically with Ruby
I wanted to export my Safari Reading List on OS X, so I wrote some code to do it. I leveraged Ruby, but this methodology could be easily ported to other languages like Bash, Python, or Objective C.
The best PGP tutorial for Mac OS X, ever
When I decided to set up my Mac with PGP encrypted communications, I could not believe how hard it was – not just to set up the software, but to understand how to use PGP properly. There was no “PGP for Dummies” tutorial for OS X on the internet. So I decided to write one. This is my über simple, nerd-free tutorial for anyone on Mac. In it, I will:
- Cover exactly how to install and configure PGP on OS X
- Demonstrate how to use PGP in real life
Creating a ruby launchd task with RVM in OS X
In the last few years, ruby has taken the world by storm. With different projects dependent on different versions of Ruby, many Rails, Jekyll, and Sinatra programmers have installed RVM to manage their ruby versions in OS X. I am one of them.
While RVM is awesome, it can make some previously simple tasks difficult. One such example is creating a launchd
daemon that invokes a ruby script. If your gems are installed with RVM, you will need to use RVM to write your daemon. That’s where it gets complicated.
This tutorial teaches you how to schedule a ruby task on OS X using launchd
. You can schedule any ruby file to be run. It will be executed using the RVM ruby version of your choice.
How to automatically move downloaded files to your desktop in OS X
Left unchecked, your OS X ~/Downloads
folder can grow into a jungle. I solved that problem by setting up an Automator script to move everything from my ~/Downloads
folder to my ~/Desktop
. Once a day, I clean off my ~/Desktop
. This is a quick tutorial how to set your Mac to do the same.
In OS X, should I use cron or launchd?
Use launchd
. Do not use cron
on OS X.
Source: the launchd
man page.
What does the at sign (@) mean in OS X permissions?
If you run ls
on a file or folder in OS X…
ls -la /dir/to/some_file_or_folder
You may see a permission entry like this:
-rwxr--r--@ 1 john admins 548 Oct 29 15:58 filename.plist
The at sign (@) means that the file has “extended attributes”. Extended attributes are basically some metadata that OS X and OS X apps can tack on to a file.
To view the extended attributes of a file, type:
xattr -l ./filename.ext
Where to put custom bash scripts in OS X
If you make a custom bash script in OS X, and you want everyone on the system to be able to access it, this is the directory where you should save it:
/usr/local/bin
How to show hidden files in Finder OS X
To show hidden files in Finder, type this into the Terminal:
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
To set things back to normal, type this:
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder