Development

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

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?

Display Hidden (dotfiles) in OS X Finder

Showing hidden dotfiles in Finder

Showing hidden dotfiles in Finder

By default, files beginning with a dot (like the .DS_Store file prevalent in nearly every OS X directory* see note below on the awesome Asepsis) are hidden in OS X’ Finder. To enable this, use the following steps:

  1. Open Terminal found in Finder > Applications > Utilities. (or use spotlight CMD+space > Terminal
  2. In Terminal, paste the following:

    defaults write com.apple.finder AppleShowAllFiles TRUE

  3. Press enter
  4. Now you need to reload Finder. I personally just type killall Finder in terminal and let Finder restart itself. An alternative is to hold alt (option) on your keyboard, then right click on the Finder icon in the dock and click Relaunch to restart Finder. Now you should be able to see dotfiles such as .DS_Store, .htaccess or .vimrc in Finder.
  5. To revert/disable this behavior, simply run the same command in the console passing TRUE instead of FALSE:

    defaults write com.apple.finder AppleShowAllFiles FALSE

Used this post as reference for this post. Contains more details and a shell alias to toggle hidden files on/off

Note that you may substitute TRUE/FALSE with YES/NO in the above commands.

* To avoid having .DS_Store contaminating your entire OS X folder structure, I recommend highly Asepsis.

Live Markdown Preview in Any Editor Using Marko.app

markdown mou.app alternative marko os x live preview vim webstorm

Marko (free) from the App Store (unrelated to an app with the same name by Marko Labs) finally fulfilled all my requirements to replace my previous Markdown editor Mou. Unlike Mou which tries to do too much and essentially is not meant to be integrated into other apps, Marko does one thing and does it well. It has excellent GitHub flavored Markdown support and it works by simply watching a Markdown file for changes you make in any external editor (my favorites are vim and WebStorm.)

Usage

Open Marko.app, then the markdown. You will see the parsed preview. Now in your editor open that markdown file and edit while Marko sits and updates live.

Command-line Usage

open -a /Applications/Marko.app ~/project/README.md

I created a console script /usr/local/bin/marko

  • Simply create that file: touch /usr/local/bin/marko
  • Give it executable permission: chmod a+x /usr/local/bin/marko
    and paste:
#!/bin/bash
open -n -a /Applications/Marko.app "$@"


(the -n here is to open a new syntax even if one exists. just a personal preference.)

Integration into JetBrains’ suite of apps

To add Marko as an External Tool to WebStorm, open preferences in WebStorm or the other JetBrain IDEs (PHPStorm, RubyMine, etc.) and under External Tools, add it with these options:

  • External Tool to execute: open
  • with the following args: -n -a /Applications/Marko.app $FilePath$

Screenshot makes this easier to understand:

markdown mou.app alternative marko os x live preview vim webstorm

To simplify this, you can create a marko script (see above) and use that in place of “open” in the external tool option and pass $FilePath$ as the argument.

Search file contents with ag—Silver Searcher, Faster than ack and grep

If you use ack or grep to search within files, check out The Silver Searcher (ag).

Installation is easy with homebrew. Open up a terminal and hit:

brew update && brew upgrade

if you haven’t updated in awhile, then to install ag:

brew install the_silver_searcher

when it’s done, type ag -h to see the options. Usage is very similar to ack/grep.

Example, let’s search every app in /Applications for curse words:

ag --stats --all-text --hidden --stats --column --context=0 -i "[^a-z]+?(asshole|whore|slut|cock|douche|faggot|fuck|shit)[^-a-z]" /Applications

outputs..


  $ ...  

  REAPER64.app/Contents/InstallFiles/Effects/LOSER/masterLimiter
   59:77:// Prevent From Preopening, I Know There Might Be Transients In Between, But Fuck'Em :/

  REAPER64.app/Contents/InstallFiles/Effects/Utility/KanakaMS5
   20:63:// so realistically this happens once or when the user changes shit.

  REAPER64.app/Contents/InstallFiles/Effects/Utility/KanakaMSEncoder1
   16:63:// so realistically this happens once or when the user changes shit.

  RubyMine.app/rb/testing/patch/bdd/teamcity/spec/runner/formatter/teamcity/formatter.rb
   435:19:            # Holy shit!!! ----> in ruby 1.8.x "instance_methods" returns collection of string and in   1.9.x collection of symbols!

  Steam.app/Contents/MacOS/tenfoot/resource/localization/tenfoot_swedish.txt
   661:36:"Checkout_Sentiment_OverOut"	"Klart slut"

  Vagrant/embedded/lib/ruby/1.9.1/rubygems/indexer.rb
   350:15:        # HACK: fuck this shit - borks all tests that use pl1

  30 matches
  23210 files searched
  229088848 bytes searched
  34.794926 seconds
$

Learn and Begin Using Markdown in 30 Minutes

Markdown, RedCarpet, Markup Language, OS X, Kramdown, Markdown Editor, Viewer, md file, mkd file, .markdown file

Markdown is a very useful tool for note takers, list makers, writers, bloggers, content architects, developers, … Markdown is essentially a common dialect for note taking. It is very close to how most of us take notes of any kind. Applying a standardized format to your static plain text content means your otherwise arbitrary notes, todo lists and essays are now formatted in a ‘markup’ language that is widely adopted and very simple to pick up and begin using right away. This means that machines now recognize elements of your content and can apply styling and other useful features.

Markdown essentially  s l i c e s  a document into a theme or presentation + the actual content. This means that you write your notes exactly the same way, whether you want a concise and structured grocery list or set of tasks for the week, or you’re writing a book that you want to release in 1 or more formats. Your single essay can be put through 3rd party software and automagically rendered as:

  • Printer-friendly HTML readable in any web browser

  • PDF file for distribution and instant accessibility to PDFs are supported

  • .epub or .mobi ebook file for reading on a Kindle or Nook

  • or published as a hardcopy book

Let’s get practical. You’re making a todo list and realize you need to make another section to group very urgent tasks. You want the urgent tasks to stand out, so you add markings and symbols in your writing to convey labeled groups of tasks. In a text document, you may add 2 empty lines to separate a group and put a line (—–) between a group name and it’s items. Done.

It’s simple. It’s plain text—readable by humans because it looks familiar to how most of us “mark up” our notes by indenting, emphasizing, underline something and using * to denote bullets prefixed to items in a list. And it’s readable by software that can now index, make searchable, add styling and accessibility features (i.e., the file is in a common machine language. I can turn it into a .mobi file to read on my Kindle, or to turn it into an audiobook that has features only possible if you can tell which unit of the file is the title and which is the body of text (like, make an audio Table of Contents.)

UPDATE 12/19/2014: I now use Marko.app over Mou. See my post on Marko and WebStorm integration.

 

Markdown, RedCarpet, Markup Language, OS X, Kramdown, Markdown Editor, Viewer, md file, mkd file, .markdown file

Install Mou – The app features a split screen. The left is where you enter your content, and the right is a live preview of your Markup/HTML content styled using one of the themes in the preferences panel. GitHub, Clearness, Tomorrow, Tomorrow+ and other CSS themes are included. While editing, hit command + R to pull up a concise Markdown Language Syntax reference.

Jeff Atwood describes Markdown accurately:

Markdown is a simple little humane markup language based on time-tested plain text conventions from the last 40 years of computing.

Markdown, RedCarpet, Markup Language, OS X, Kramdown, Markdown Editor, Viewer, md file, mkd file, .markdown file

Mou is a free Mac OS X Markdown Viewer and Editor