Optimization

WTF is a “command” or “passing arguments”? Making Sense of the Command Line

Meow Meow.. Let’s understand how commands, “passing things” to them and “executing” or “running” them works in the terminal/shell by giving hard definitions for what we think we understand a term (pun intended) to mean and how the operating system, shell, scripts, apps, commands, functions and arguments work and how our mental model of them may be (very) skewed.

The following command will replace the prefix for screenshots you automatically capture or crop to your desktop in OS X to “SS” instead of the default “Screen Shot”, just to use as an example. If hit cmd+space type ‘term‘ and wait for ambiguities or hit Return. A terminal window or “shell” where you can type stuff hopefully opens. WTF just happened?

You hit a universal OS X shortcut that runs Mac’s built in open command to execute some binary file (meaning a compiled source file) somewhere in Spotlight.app
Then pass its main function 1 parameter, a string argument with a value of “term”- it does a fuzzy or wildcard search in the index of every single file/directory on your machine (except those you exclude)
defaults write com.apple.screencapture name “SS” && killall SystemUIServer

 

defaults.write(defaults.get('com.apple.screencapture').name('Screen Shot')

Let’s define some terms first

Kernel is the OS itself. The set of “functions” people at Apple, people they contracted and people before them wrote you’re running on the very expensive hardware Apple sold you. The Kernel class is a blueprint or sketch on a napkin, or a form of Plato’s kind, not a tangible thing, except in the following code syntax context, where tangible means a thing you can make instance an of, copy, mutate, read, write-to, etc. A tangible class is an instantiated object, rather than being an abstract class. Thing of a chair class vs an actual chair. Your physical body cannot sit on an abstract chair. It must exist. The “abstract chair” itself cannot just transform to a wooden tangible chair that follows the same rules as your body. It is only an idea, an electrical pattern humans conditioned themselves to agree on so solidly that we can build/import/export/buy/sell/make-shift/DIY/fix and do a million other things with this concept of a chair.

A Tangible class means an object and an abstract object means a class. Kind of. Avoid these terms. They are only here as a koan to break you from your usual stream of consciousness.

`kill` is a function, procedure or method, a “verb” on the concrete object. You can and do have abstract functionality on abstract objects (aka classes),

 

function killall(name) {
   var SIGNAL_TERMINATE = 15;
   Kernel.kill(Kernel.findIdByProccess(name), SIGNAL_TERMINATE);

defaults is an app, probably written in a language called C or in another call =ed Objective-C and compiled. It could also be written in Ruby, Python, Java, Javascript, Lua, or another interpreted language (“script”) that has its “executable” permission set ON. If you see something like |rwx-rw-r defaults| It is simple in that it probably is written to serve a single purpose. The Unix philosophy is “Write something that does one thing and does it well.” “one thing” is relative. Is “email” one thing? Is browsing the web “one thing”? It used to be, but now browsers are extremely complex pieces of architecture that seemingly do different things for different user archtypes.

 

killall SystemUIServer

Hard restart of the SystemUIServer (just an app running in the background. You can also kill it the hard way without a terminal by killing it using killall after defaults succeeds (the && is important)
killall SystemUIServer

 

Terminal/iTerm2/console/shell/Bash/Zsh.. are these synonymous?

Turn Off Animations (Instant Transition) in Mission Control / Exposé on OS X Yosemite, Lion, Mac

mission-control-disable-animations-annoyingThe following will let you turn tweak or completely turn off the animations for Mission Control (still called Expose in some places.) This works for Lion, Snow Leopard, Mountain Lion, Mavericks, Yosemite and probably the next version of OS X. Unfortunately, you can tweak nearly every animation except the slide when switching screens. See the post linked to on the bottom or click here to see how you can bypass OS X’s native Mission Control / Expose window manager and use a sweet 3rd party app called TotalSpaces. See my previous post about using VirtualSpaces to completely turn off/disable swype/slide/transition animation when switching desktops or screens in OS X Mavericks and Yosemite.

 

 

If the gestures listed below don’t work, you will need to enable them (yours may vary depending on your hardware/OS/settings) Thanks to this StackOverflow answer for the command below:

defaults write com.apple.dock expose-animation-duration -int 0 && killall Dock

And to go back to defaults run:

defaults delete com.apple.dock expose-animation-duration && killall Dock

This turns off the annoying animations for Mission Control
(aka Expose) including:

  • Mission Control (swipe up with four fingers or keyboard shortcut)
  • App Exposé (swipe down with four fingers or kb key)
  • Launchpad (pinch with thumb and three fingers, like a crab, or those machines you put a coin in that have a claw which never seems to be able to grip on the toy you’re aiming to get.)
  • Show Desktop (spread thumb and three fingers, opposite of Launchpad gesture ^)

but unfortunately it does nothing for the following animations:

  • Notification center sliding in (2 finger gesture from right edge of trackpad or using kb shortcut)
  • Swiping with 3 fingers on the trackpad to switch between full screen apps
  • Switching desktops (whether using your gesture or dedicated keyboard shortcut per screen/desktop)
  • Switching back <> forth pages in the Safari browser

Reduce window resizing animation speed (I’ve had mediocre results with this):

defaults write -g NSWindowResizeTime -float 0.001

or revert to default:

defaults delete -g NSWindowResizeTime

You’ll have to quit the applications you’re using for this to take effect.

PRO TIP:

It would be nicer if when we made changes using `default`, we somehow kept a log of what we’re doing. Something like ~/.zhistory or ~/.bash_history would be nice. to save these exact commands you’re probably copying and pasting from strangers on the Internet. This is possible with very little knowledge of shell scripting and only a single alias command.

First is the one liner. This will create a temporary file, ask if you want to proceed before blindly applying the new value to the key for `com.apple.dock expose-animation-duration` and then prompt you that Dock is restarting and shows you how many commands (lines) are in that temp file. This is to disable the animation and see this in action on one line:

: ${tmplog:=`mktemp -t ohmytosh.com`} && echo "Writing these files to log $tmplog just in case. Proceed?" && read && echo "defaults write com.apple.dock expose-animation-duration -float 0.1 && killall Dock" >> $tmplog && defaults write com.apple.dock expose-animation-duration -float 0.1 && killall Dock && echo "restarting Dock.. you have `cat $tmplog | wc -l` lines in your temp file"

Here’s the line broken down to make it easier to read:

 

: ${tmplog:=`mktemp -t ohmytosh.com`} && # assign value from `mktemp` to $tmplog if this var is null
echo "Writing these files to log $tmplog just in case. Proceed?" &&
read && # wait for user input (ctrl + C cancels this entire line due to the &&'s)
echo "defaults write com.apple.dock expose-animation-duration -float 0.1 && killall Dock" >> $tmplog && # write command to logfile 
defaults write com.apple.dock expose-animation-duration -float 0.1 && # run the actual command
killall Dock && 
echo "restarting Dock.. you have `cat $tmplog | wc -l` lines in your temp file" # some user feedback. use unset $tmplog, though it will be unset if shell closes.

Upcoming posts: How to use a 3rd party app to avoid viewing the desktop/screen slide animation 50+ times a day and how to put the above into a re-usable shell alias. For now, see how I did it using VirtualDesktops years ago. Nowadays I use TotalSpaces.

If you’re a developer you’ll see some repetition here (violation of Don’t Repeat Yourself, or DRY) but should this be DRY, it’s still a hassle to type out, especially if we’re working a lot with `defaults`. Perhaps we can make this more robust but general enough to use elsewhere, a shell alias perhaps? for next time…

Increase Contrast Checkbox Results in Slightly Snappier UI on OS X Yosemite

 

 

Checking the Increase contrast under Accessibility > Display checkbox can result in a small but maybe significant performance boost for the UI elements in Yosemite. You lose some of the transparency and near shadowing as a sacrifice for harsher darker borders, amongst other small things.

How? By going to  > System Preferences > Accessibility > Display, and ticking the Increase Contrast box does the trick.

I happened to make my cursor size huge to make it easier to see. Especially useful on a 4K display.

large-cursor-increased-contrast

Tips for Speeding Up OS X

The following are tips for speeding up OS X. First let’s get the common tips out of the way:

1) Stop/remove all animations (window opening/closing/minimizing, etc.)

2) Get CCleaner for Mac and run “Analyze” then do a full run and let  CCleaner get rid of caches and such.

3) Limit folders/filetypes that Spotlight indexes and re-index Spotlight.

4) rm ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2

5) Delete the Quarantine files here:

~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2
~/Library/Preferences/com.apple.LaunchServices.QuarantineEvents

by prefixing the above with “rm<space>” using the Terminal application. To find that, use Spotlight (CMD + Space.) and type “Terminal<Enter>”