Apple TV Tech Talks Videos

Apple TV Tech Talk Videos

Apple has released the videos for the Apple TV Tech Talk, a conference that it held across 10 cities around the world to teach developers how to make tvOS apps for the Apple TV. There are a total of 11 different videos covering topics from designing for tvOS, focus-driven interfaces, Siri Remote controller, on-demand resources, TVMLKit, the Top Shelf and App Store distribution and marketing. This is the first online video resources from Apple to learn about Apple TV programming as tvOS was not covered in WWDC 2015.

Basic command line editing keyboard shorcuts in OS X

Basic command line editing keyboard shorcuts in OS X 

This post is part of a series of tutorials on OS X command line. Please read the following first to get started:

We continue our exploration of OS X command line by highlighting editing keyboard shortcuts in the Terminal app. These keyboard shortcuts described are the default editing settings for a terminal running bash shell under OS X. Many of the keyboard shortcuts will also work in standard text field you encountered in any Mac app.

  • Right Arrow or Control-F to move the cursor forward one character
  • Left Arrow or Control-B to move the cursor backward one character
  • Delete key or Control-H to delete one character
  • Control-D to forward delete one character
  • Control-A to move the cursor to the beginning of line
  • Control-E to move the cursor to the end of line
  • Control-K to delete everything from under the cursor to the end of line
  • Control-U to delete everything from under the cursor to the beginning of line
  • Control-W to delete from under the cursor to the beginning of the word
  • Esc-F to move forward one word
  • Esc-B to move backward one word
  • Control-R to recall previous command by searching through command history
  • Control-T to transpose (swap) with one another the two characters before the cursor
  • Esc-T to transpose (swap) with one another the two words before the cursor
  • Up Arrow or Control-P to go back previous commands in history
  • Down Arrow to forward previous commands in history. It is the reverse of Up Arrow/Control-P.
  • Tab to auto-complete name of file, folder or program
  • Control-L or Command-K to clear the screen 

The above is not an exhaustive list of all editing shortcuts and capabilities, but is sufficient as a starting point to get you productive on the command line.

Getting around the Terminal in OS X

The Terminal app in OS X presents an old school command line interface, but sports modern configuration to change the font, background color and other advanced shell options. Go to Terminal app’s Preferences… and click on the Settings tab to configure terminal settings.

Getting around the Terminal in OS X Default Profile

Profiles

Settings are grouped under profiles and Terminal comes with a number of stock profiles such as Basic, Grass, Homebrew, Man Page, Novel etc to get you started. Each profile comes with a separate configuration for the font, background color, window, shell etc settings. You then specify the profile to use when you open a new terminal window.

Getting around the Terminal in OS X using profile

You can specify a profile as default by selecting the profile and click on the Default button at the bottom. The default profile is the settings used when you open a new terminal window using Command-N.

You can add a new profile by clicking on the ‘+’ button. And you can remove a profile using the ‘-‘ button. When creating a new profile, it is advisable to duplicate the settings of one of the stock profile.

Getting around the Terminal in OS X Duplicate Settings

Tabs

It is typical for person who is fluent in using command line to open a number of terminals while working on their Mac. You can open terminals in separate windows, or you can open them in tabs similar to Safari and Finder. Use Command-T to open a new terminal in a tab. 

Getting around the Terminal in OS X Tabs

Give it a try to see if working with tabs suit you better. It is a matter of personal preferences.  

Closing a terminal

You can close a terminal in a window or tab by using Command-W. Or you can simply close the terminal window by clicking on the red close button at top left corner of window. These are OS X system methods of closing window, and is forcefully closing your terminal including any running commands.

To properly end a terminal session, it is a good habit to enter the exit command instead. This will ensure no hanging running process and a clean exit.

Getting around the Terminal in OS X Exit

Once the exit command is entered, bash shell will logout your session and display a message “[Process completed]”.

At this point the terminal is dead and you can no longer enter any further command. The terminal window however is left open and you have to issue Command-W to close it. You can setup your terminal profile so that window is automatically closed after an exit command.

Go to Terminal > Preferences > Settings and select the profile. Under Shell tab for the option When the shell exits, select the option Close if the shell exited cleanly.

Getting around the Terminal in OS X close window

Note: This is a continuation post of a series of tutorials on OS X command line. Please read the post Basic OS X command line utilities and tips to get started.

Basic OS X command line utilities and tips

OS X comes with a powerful command line interface as with any operating system derived from Unix. Before the age of graphical user interface, command line is the only way for human to interact with computer.

At the heart, command line is the place where you key in commands and programs, and the command line interface will run them for you. You can also combine commands into a script file and run them all at once.

To get access to the command line interface, run the Terminal app which is available at Applications > Utilities > Terminal. You might want to add the Terminal app to the dock. 

The prompt

When you first launched the Terminal app, it will open a command line window with a prompt similar to:

Last login: Mon Mar 24 11:15:38 on ttys001
$

It tells you when is your last login time, follow by a “$” prompt. The prompt is now waiting for you to enter command.

The command line prompt is customisable thus you might see a different symbol or text other than “$”. For example it is common to format the command line prompt to contain your computer name and user name.

machome:~ sandy$

In the above example, “machome” is the computer name and “sandy” is the user name. You will see a different prompt on your Mac depending on the setting of the prompt. We will describe how to customise the prompt in a future post. 

The shell

You can open one or more shell window under Terminal app, and they each work independently. As shown below, you can customise the color and font for each shell window under Terminal.

Basic OS X command line utilities and tips multiple windows

For each window that you open under Terminal, the app is running a shell program that handles the interaction with you. There are a number of shell programs available to serve as the command line interface. Popular choices include Bourne shell (sh), C Shell (csh), Korn Shell (ksh) and Bourne-Again shell (bash). Each shell program varies with each other by means of default command behaviour, settings files and syntax when writing shell scripts.

OS X comes with bash as default shell. You can off course change the shell according to your liking. We will be focusing on bash for this and future posts.

You can use the echo command to check the shell that your terminal is using:

$echo $SHELL
/bin/bash

For the above, we issue the echo command to print out the environment variable “$SHELL” which hold the value of the shell program.

Working directory

There is this concept of current working directory when you’re at a command line prompt. This is simply the directory you’re on when issuing a command at the prompt.

When you open a new terminal window, by default the shell program will land you at your home directory under /Users/.  Issue the pwd (print working directory) command to check your current working directory:

$pwd
/Users/sandy

Current directory is important as commands and tools will assume it is the working directory unless otherwise stated. This is especially so for commands that act on files on a directory.

Listing directory

You can list the content of the directory using ls:

$ ls
Applications
Desktop
Documents
Downloads
Library
Movies
Music
Pictures
Public

You can display more detail info using the “-l” parameter of ls:

$ ls -l
total 217952
drwx------ 3 sandy staff 102 Jan 19 01:26 Applications
drwxr-xr-x+ 20 sandy staff 680 Mar 24 09:28 Desktop
drwx------+ 10 sandy staff 340 Mar 19 12:45 Documents
drwx------+ 50 sandy staff 1700 Mar 24 09:07 Downloads
drwx------@ 74 sandy staff 2516 Jan 29 03:43 Library
drwx------+ 8 sandy staff 272 Mar 19 12:45 Movies
drwx------+ 6 sandy staff 204 Mar 19 12:45 Music
drwx------+ 11 sandy staff 374 Mar 19 12:45 Pictures
drwxr-xr-x+ 6 sandy staff 204 Mar 19 12:45 Public

The above shows how typically one uses parameters to change the behaviour of a command.

Changing directory

You change the current working directory by using the cd (Change Directory) command. To change to your Documents directory:

$ cd Documents
$ pwd
/Users/sandy/Documents

If you do not specified any parameter to cd, the shell will change the working directory to your home directory:

$ pwd
/Users/sandy/Documents
$ cd
$ pwd
/Users/sandy

Home directory is also represented by the symbol “~”:

$ cd ~/Desktop
$ pwd
/Users/sandy/Desktop
$ cd ~
$ pwd
/Users/sandy

 To go back one directory level up, use “..”:

$ cd ~/Pictures
$ pwd
/Users/sandy/Pictures
$ cd ..
$ pwd
/Users/sandy
$ cd Music
$ pwd
/Users/sandy/Music
$ cd ../Applications
$ pwd
/Users/sandy/Applications 

Get help with man

To get the help page for a command, use the man (Manual Page) command. The help page is also called a man page. Thus to display the man page for ls command:

$ man ls

Basic OS X command line utilities and tips manual

Use the arrow key or space bar to scroll the manual page. Press the “q” key to quit.

Auto Completion

When you’re entering command line parameters, use the tab key to auto complete directory and file name. Type the first few characters, and then press the tab key, and the command line will fill the rest for you.

For example when at you home directory, and to navigate to the Desktop folder, enter “cd De” and press the tab key. The shell will fill up the command line with “cd Desktop” for you.

Warnings

Please note that command line interface gives you all the power to control your computer, up to the point of total destruction. Thus it is important to understand a command before you run it.