Effectively Managing Too Many Desktops & Screens on Mac OS X

BToo Many Virtual Desktopseing able to create virtual desktops can increase productivity significantly. With multiple virtual desktops per monitor and people opting to use more displays as technology allows it (MacBook Pro Retina has 2 Thunerbolt and 1 HDMI port, along with a damn nice retina display and the possiblity of daisy-chaining displays and buying external adapters to add even more screens) the complexity of managing so much screen real estate may come at the cost of some productivity.

How Much is Too Much?

Can’t have enough, as long as it’s managed properly, but it also depends on what you do and the specs of your machine. It’s great that Apple is relatively recently allowing you to add more than one external display to your Macbook Pro so easily, they hinder resources by soldering on the amount of RAM in those machines. Terrible. Even with 32 GB of RAM, an iMac and 3 external displays, I didn’t feel like I had enough. Now down to an i5 Macbook Pro Retina with 8 GB of RAM and 3 screens with 4 virtual desktops (1 for each screen, so 12 desktops in total),

Wrapper around Property List Util to Convert between XML1 & BINARY1 formats

Xcode Property List Converting Formats Binary to XML

Ever found you had to change the value of Disque Dur Vierge in the French resource of        SystemUIServer.app? No? Good. If so, this small wrapper may help. The normal procedure is to locate the string in the resource, (no linting here, create a backup before touching these files!) convert it from “Apple binary property list” (pass binary1 as arg to –convert flag on plutil) to “XML Document text” (argument you pass plutil is xml1 instead), go at it with your editor of choice, save and convert back to binary1. Then send a TERM signal to SystemUIServer (via killall) to restart and see your changes. If this paragraph is confusing or you’re interesting in learning this stuff more, refer to my last post, WTF is a “command” or “passing arguments”? Making Sense of the Command Line.

 

 

 Manually (old fashioned way)

 

pushd /System/Library/CoreServices/SystemUIServer.app/Contents/Resources/French.lproj/
sudo plutil -convert xml1 InfoPlist.strings
sudo vi InfoPlist.strings
sudo plutil -convert binary1 InfoPlist.strings
popd

With this property list format helper script

(code pasted below) placed in ~/bin (create if it doesn’t exist) which is in my ~/.PATH (create if it doesn’t exist) that’s sourced in my ~/.zshrc or ~/.bashrc etc.

Script Usage

sudo update-plist.sh InfoPlist

down to 1 line from 5 and 1 sudo from 3, respectively.

or (if script not in $PATH)

cd ~/Downloads
sudo ./update-plist.sh InfoPlist

Troubleshooting: You may want to set the executable flag on owner (o+x) on the script. May need to prefix with sudo or run in su

The Code, pasted from the GitHub Gist

#!/bin/sh
#
# A script to make it easier to edit resources in mac.apps on the commandline
# Isam M 2015 <http://github.com/lsd/update-plist.sh>

# exit if pipeline (1+ cmd) fails
set -e

echo
echo "USAGE (default English): To open ScreenCapture.strings in SystemUIServer.app/C/R/English.lproj
echo "$ sudo update-plist.sh ScreenCapture
echo

# hardcode English ...
# LANGUAGE="$1"
RESOURCE="$2".strings

LANGUAGE="English"
RESOURCE="$1".strings
DIR="/System/Library/CoreServices/SystemUIServer.app/Contents/Resources/$LANGUAGE.lproj"

# cd in, validate resource, make backup
pushd "$DIR"
ls -l
echo
diff "$RESOURCE" "$RESOURCE" 2>/dev/null
BACK=~/".$RESOURCE.binary1.`date -j +%S%s`.back"
cp "$RESOURCE" "$BACK"
echo "Backed up resource $RESOURCE to $BACK"

# Convert to XML, open in vi, when done convert back to binary
sudo plutil -convert xml1 "$RESOURCE"
sudo vi "$RESOURCE"
sudo plutil -convert binary1 "$RESOURCE"

# Clean up
mv "$BACK" /tmp
popd
echo
echo "Restart SystemUIServer? (ctrl+c to cancel)" && read
killall SystemUIServer


* See latest revision at gist.github.com/lsd: Wrapper around `plutil` to quickly jump between xml1 and binary1 when editing plists

Crop Custom Part or as PNG to Desktop with cmd+shift+4 OR cmd+shift+3 for FULL Screenshot

 

<Clippy> OS X? pfft, how can I print full desktop screen prints like in Windows?

<Clippy> What’s the Mac/OS X alternative to the clumsy prnt-scrn (print screen) > paste > MS Paint > save > name and format (oops, saved as useless .bmp again?) > find the file (and possibly resize it if you forgot the first time around) > use file > delete > possibly repeat enter process > or clear clipboard if Windows is feeling sluggish, even if the perceived latency or load is purely psychological. Nothing subjective matters when your brain is subjectively seventeen times slower than “real” time.

Snippet of Desktop Screen Instantly Automatically Saves to BG

Shortcut to Crop Rectangle &  Save PNG to Desktop (or change default location/format)

The shortcuts use any combination of the left and right command/shift keys and either the number 3 (full screenprint) or 4 (crop rectangular area) If you want to workout your fingers, use use leftCommand + leftShift + rightCommand + rightShift + 3 (or 4)). Here’s the result, two screenshots,

In Mac OS X (From Yosemite to Maverick to Snow Leopard to Lion, etc)*, you can crop any part of any screen on any monitor you have running, anytime by using Command + Shift + 4 and check the desktop for a new image. (It helps to have it sorted by Date Modified)

Use Command + Shift + 3

and check the desktop for the new image(s).

Unclutted Your Desktop (Change location and format of stored shots/prints

Soon your desktop will look like this:

changing filename screenshot mac os x yosemite

Change Prefix of Default Screenshot Name Saved to Desktop

defaults write com.apple.screencapture name “___ss” && killall SystemUIServer

Restore name to default “Screen Shot” prefix

defaults write com.apple.screencapture name "Screen Shot" && killall SystemUIServer

WTF is a command or “defaults” anyway? The command line structure and syntax, dissected and easy to visualize.

Change Where Captured Shots Instantly Get Saved In

Instruct, invoke, run, execute, call the defaults cmd, which like most commands isjust the name of an app your Terminal.app (make sure it's open!, use SpotLight) or iTerm or other terminal emu or shell is aware of (technically it exists in your shell's $PATH variable) (usually) should write 3 underscores as a prefix to shots stored in ~/Pictures/Screenshots

Change the Format of the Saved Screenshot to JPG, TIFF, PDF, GIF or default PNG

defaults write com.apple.screencapture type jpg
defaults write com.apple.screencapture type tiff
defaults write com.apple.screencapture type pdf
defaults write com.apple.screencapture type gif
defaults write com.apple.screencapture type png

*pro tip: To avoid repetition in documentation and tutorials, we can put all choices between square [ brackets ] and delimit or separate each choice with a vertical pipe |. The result is [only|one|of|these|words|not|all]. The above 5 calls to default can be abbreviated, ie in their man/documentation pages as:

defaults write com.apple.screencapture type [png|tiff|jpg|pdf|gif]

though typing all of this out would be invalid. You just have to learn that a pipe | is an OR, as you agreed that in literature (or major languages) an ampersand & is an AND. Just remember it.

Read current format Images get Saved As

defaults read com.apple.screencapture

Tip: This is how you read any of these “OS X user defaults”. The Command Line Explained in Detail. To see the documentation, type

man defaults

in the Terminal/iTerm/shell/Bash/Zsh and hit enter to read the manual page. press q or Q to quit and the UP arrow to cycle through the last commands you ran in descending order.

 

Troubleshooting / Screenshot shortcut doesn’t work?

It’s the number 4, not F4, ensure exclusively three keys held. If you can’t locate the images, open up Finder (Command + Space, type finder and press Return when it’s found (usually by the 3rd letter, ‘fin’. Typing nothing else and waiting will drop down mixed results. )

* You can do this in Microsoft Windows 7, Windows 8 or above by using the included SnipperTool.exe (type it into the Start > Search bar, then create a shortcut to it on your Start Bar and/or create a universal shortcut for it. and in Linux and other versions of Mac or Windows (XP, Vista, etc) using third party apps or browser extensions if you’re only interested in grabbing screen captures/crops within your browser.

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