OS X for Linux people

From DiLab
Revision as of 09:54, 21 July 2019 by Leo (talk | contribs) (Backup with cp)
Jump to: navigation, search

So you just run into a Lion or some other animal from OS X. I just did, too. If feels like roaming through jungle while looking for gems. And finding them.

Some might call this

"10+ things to do with MAC OS X/Macbook Air/Pro/Mini after you got it".

Let me share some simple things that took time. This is mostly about OS X 10.7+ Lion and Mountain Lion, which is the current version at the time.

Update: I just got a new Macbook Air. Given the experiences from before, let me share my Macbook Air install log (2013 version)


Impressions and differences

...the good

  • Safe-mag power connector is the best. just sticks to the place, from front and behind, shows the status with a LED, and pulls off without effort.
  • I like how the keyboard responds. Soft and quiet.
  • The backlight under the keys is nice, and should probably be used in most such input devices.
  • Multi-touch is nice and easy to get used to. Especially the scrolling, and moving windows (enable the 3-finger move in system prefs)
  • Most installations for new software is easy. Download and click on *.dmg file. Maybe drag the new software icon to Applications. Enjoy (or hate) the new spoils.

...the bad, and sometimes ugly

  • Now, the backspace key is called delete and does backspace (like in the old days). But where is the delete key...? Oh, well, it turns out you can press Fn+delete for the delete functionality.
  • I am too used to linux/win control and alt key functionality. This throws me off. For example, I just accidentally switched panes again when wanted to jump a word back (pressed Ctrl+Left instead of Option/alt+Left).
  • Integrated AppStore is ok, but rather limited, understandably so, to approved software. Oh, well, one can find many alternative software choices on the Internet, as already precompiled .dmg files.
  • The Finder file manager. I miss being in control of my files, and split/tab views, and folders being on top, and other things Nautilus and many Linux/Windows browsers have. Thankfully, there are some remedies, like the TotalFinder (not free) or MacPorts with Nautilus.

Simple things

Right click?

Easy. Tap (or click) two fingers.

Tired of pressing that click on the Macbook?

Switch to "tap to click". System Preferences -> Trackpad -> Point & Click -> check Tap with one finger. It is quieter, too.

I also enabled the three-finger move. Makes them window movement and text selection easier.

Keyboard shortcuts

Delete key confusion

The usual backspace key is named delete on Macbook, but it does backspace, which is fine. But where is the Delete key that does forward-delete? No such key.

But you can use Fn+delete to do forward delete. I guess the old typewriter keys dod not have a notion of deleting what has not been typed yet, and therefore did not include such key on the keyboard. Sometimes Apple is conservative...

A few other useful shortcuts

  • Fn+up/down is page up/down
  • Fn+left/right is home/end
  • Alt+delete will delete a whole word. Command+delete will delete the whole line to the left
  • Fn+alt+delete will delete the next word forward.

Keyboard remapping

Control+arrow switches desktop panes. But I want it to jump words. This is where a keyboard remapping software, such as KeyRemap4MacBook comes in. Download and install it, then choose what keys or combinations change to what. My favorite remappings, coming from the PC world:

  • Control+Arrow to Option_L+Arrow, to get the control to skip words, not desks.
  • Command_R to Option_R, or else I keep pressing command+a to get 'ā' for my Latvian text, but it selects everything instead, and kills the text with the next stroke.
  • Option_R to Forward-Delete, to get my Del key back and close.
  • Z+X to Left click (to make drag and drop easier with the touch pad)

File manager

The stock file manager is called Finder. There is a reason there are websites to tell you how to make it suck less by enabling the path bar, adding tabs, panes, folders on top, and other good, basic things, or to replace it altogether (PathFinder).

If you feel the pain, I suggest to try TotalFinder first, which adds some features to the default finder, including tabs and an option to sort files with the folders on top. It is free for 30 days, or $18 to buy at this time.

Terminal

Where to find

You could search most things by clicking on the search icon at top right corner. Then type "Terminal" and see the options below.

Or you can go and explore the Launcher. Slide two fingers right to get the left pane, and you see the system (preinstalled) apps. The right pane show the downloaded or purchased apps that are installed. Go to the left pane Utilities -> Terminal to get the terminal.

I still want to create a systemwide shortcut for new terminal... TODO

Terminal auto-close on shell exit

OK, I press Ctrl+D to exit the terminal and it nicely tells me:

...$ logout
[Process Completed]

Thats not enough. I want the window to close when I am done. And this is what we need to do:

  • Start the terminal
  • Go menu -> Terminal -> Preferences -> Settings -> Shell -> "When the shell exits:" set to "Close if the shell exited cleanly"
  • Close the Settings window

Now the Terminal window will close on Ctrl+D. It will also close when other programs invoke the shell and exit with no errors. If they have errors, the terminal will stay open so you can read about what went wrong.

How to open apps from terminal

For example, I would like to start TextWrangler editor from the command line. If you just type the app name, this wont work. Instead, type "open -a" and the app name. Or better yet, create a short alias for that app, and put it in your startup script (.bash_profile or .bashrc) For example, lets create a command line shortcut "tw" that will open the TextWrangler:

alias tw='open -a textwrangler 

There is no place like home

Well, there is. It (the directory) is called Users, not home. For example, JOHN will have his home at /Users/JOHN, instead of /home/JOHN. Be prepared to love $HOME in your shell scripts instead of the explicit pathnames with "home" in them.


Where's my apt-get install?

Not there. But there are:

  • MacPorts that you may want to install to ease the path to other open source software. Mind, that many of the packages will compile from source and drag all the requirements with them. This will take time and space.
  • Homebrew. Mostly easier than macports, but fewer packages, although the macports cound several versions of applications as separate packages. Homebrew is striving to depend on native OSX resources when available.
  • There is also Fink, that I won't talk about much here.

Where is my .bashrc ?

You want it - create it. You might also want to create and add the following in your .bash_profile, because .bashrc will not start automatically.

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Wine, please

for my windows stuff, such as old Visual Basic programs.

Alternative ways to do windows on Mac are:

May I recommend Winebottler? This will take care of your wine in a quick and rather painless way.

Mind you, winebottler was not friendly with Parallels on my Mac.


Wine with MacPorts

Here is one how-to: http://www.davidbaumgold.com/tutorials/wine-mac/

What this tells you to do is:

  • Set up Xcode from apple (free from AppStore)
  • Install "Command line tools" from Xcode - registration required as an apple developer
  • Download and set up MacPorts, so you could run "port install wine".
  • Install wine using MacPorts from the terminal. Then have a rather long coffee or tee or just nap while everything downloads and compiles.
sudo port install wine
  • I'd add that you will probably need and like to add winetricks. This will ease the installation of various dlls and components needed for your windows programs, such as mfc42.dll.
sudo port install winetricks

Starting apps form the command line

OK, I got the terminal. I even got nano. But I want, say, TextWrangler to edit my text file. How?

Use "open". For example, if you want to edit your .bashrc then do this:

open -a TextWrangler .bashrc

Haha! Now I can create alias(es) for my favorite apps to be invoked from CLI. You could, too. Here is more info

Add recent servers, documents,... to the Dock

I have a linksys e4200 wireless router with a USB drive attached to it. Unfortunately, my Mac forgets about the shared drive. I wanted to add a shortcut to it somewhere, and finally found a way: Add a stack with "Recent Items" to the dock. This is the magic:

  • Start the Terminal, and enter the following:
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }'
  • The Dock will disappear and appear again after this:
killall Dock
  • Close the terminal. You should have a "Recent (something)" icon on the right of your Dock. You can change the properties with two-click (right-click) on it to show the recent Servers or what fits you.

More info here: here.


Encript folders with EncFS

EncFS is a cross platform virtual file system that mounts a volume over one directory and encrypts everything written to it to another physical directory.

EncFS is installed as follows:

  • Install OSXfuse
  • Install EncFS using homebrew:
brew install encfs
  • Use Encfs to mount an encrypted volume
encfs ~/Dropbox/Private.enc/ ~/Private/
# or with a custom volume name
encfs ~/Dropbox/Private.enc/ ~/Private/ -- -o volname="Dropbox private"

Useful applications

There is a list of some applications or packages that I set up on my Mac.

...from the AppStore

  • The Unarchiver - to get them archives unfold
  • TextWrangler - text or source code editor
  • MPlayerX - video player inspired by the classic mplayer
  • Smart Converter - between video formats
  • Keynote - for presentations. Beats Powerpoint at $20.
  • Xcode - useful and free from apple for development or installing some other packages.
  • Karabiner-Elements - redefine the keyboard keys and add shortcut combinations

...from the Internet

System and tools

Less often used

  • Ukelele - a keyboard layout editor. But it cannot change the modifier keys, such as control, option, command.
  • Sophos antivirus - free, MAC home edition

Applications

  • VLC - plays almost any type of video
  • PSPP - a statistical software like SPSS, but under GNU licence.

Recovery

Things happen. it may be that your mac acts up and you need to troubleshoot the boot process and recover your data.

Backup with cp

One way to backup your data is to plug in a USB drive and boot into recovery mode with pressing CMD+R while booting. From there you can use the Disk utility to check the integrity of the disk. After that you can close the disk utility and open a Terminal and use unix commands to troubleshoot and also to backup your data.

Note, another way to enter a terminal would be booting it a single user mode (Ctrl+S down while booting), but mounting a USB drive or recognizing it might proove to be a challenge. In the Recovery moe it was mounted automatically, and you can also verify its integrity before the backup, if you wish.

There are ways to do backups Macos way, however the story below is how to do it Unix way using cp command. Another way would be to use rsync, but that was not available for me in the recovery mode.

Tasks:

  • You may want to make your file system read and writeable. Optionally check it for defects before:
/sbin/fsck -fy 
/sbin/mount -uw / 

Mount the USB drive (unless automounted)

  • Find the USB disk device. The usb disk is likely to be the last one, e.g. disk21s1
ls /dev/disk*
  • Make a directory for the mount point:
mkdir /Volumes/usbdisk
  • Determine the type of the filesystem on the USB disk (NTFS or FAT or HFS or ...)
fstyp /dev/disk2s1
  • it is likely that the USB disk is already mounted (find it under the /Volumes/...) in read only mode. You may mount it in read write, but before that unmount the old location:
umount /Volumes/MyUsbDrive
  • Mount the disk as a read-write, so you can access its filesystem with the regular commands
      • For the NTFS file system:
mount -t ntfs -o rw,auto,nobrowse /dev/disk2s1 /Volumes/usbdisk
      • For the FAT file system
mount -t msdos /dev/disk2s1 /Volumes/usbdisk
      • For the HFS (mac) file system
mount -t hfs /dev/disk2s1 /Volumes/usbdisk
  • Copy the files, preserve attributes ("-p"). "-X" is for not copying the access lists and resource forks to avoid copy errors to NTFS.
cp -npRXv "/Volumes/MyMainMacDisk/Users/myuser" "/Volumes/usbdisk/mybackup/myuser"

Note, that in the recovery mode the computer may enter sleep mode and stop the backup after a while. To prevent this you can use caffeinate command. Ctrl+C to exit the no-sleep mode, e.g. when done copying.

caffeinate

If you want to keep the display awake as well, use a stronger command version:

caffeinate -dismut 65500

This should keep the computer awake for some 18 hours.

  • Finally, when the copying is done, you can unmount the USB disk before shutting down the computer:
umount /Volumes/usbdisk

or

umount /dev/disk21s1

Resetting a new user account on macos

From a single user mode (press Ctrl+S while booting)

mount -uw /
rm /var/db/.AppleSetupDone
shutdown -h

This will:

  • Re-mount the internal hard drive with write permission
  • Remove the Mac setup file. This is the file that OS X checks to determine if the system is already set up.
  • Shutdown the Mac

Then restart and you should be prompted for a new user account.