Jul 04, 2015 It'll reset your Dock to its default settings, just like when you first took your Mac out of the box. Default apps will be restored to their standard locations, and preferences like magnification, hiding, and so on, will be reset. Everything will be reset. How to reset your Dock to its default. Open Terminal (located in the Utilities folder). Dec 19, 2012 If you accidentally permitted a Mac app to gain access to things like your personal contacts list or location, or you’d just like to start over again and have granular control over which applications can access certain data, you can use the command line tool tccutil to change this and reset Mac app access to personal data.
The user defaults system manages the storage of preferences for each user. Most preferences are stored persistently and therefore do not change between subsequent launch cycles of your app. Apps use preferences to track user-initiated and program-initiated configuration changes.
What Makes a Good Preference?
When defining your app’s preferences, it is better to use simple values and data types whenever possible. The preferences system is built around property-list data types such as strings, numbers, and dates. Although you can use an
NSData object to store arbitrary objects in preferences, doing so is not recommended in most cases.
Storing objects persistently means that your app has to decode that object at some point. In the case of preferences, a stored object means decoding the object every time you access the preference. It also means that a newer version of your app has to ensure that it is able to decode objects created and written to disk using an earlier version of your app, which is potentially error prone.
A better approach for preferences is to store simple strings and values and use them to create the objects your app needs. Storing simple values means that your app can always access the value. The only thing that changes from release to release is the interpretation of the simple value and the objects your app creates in response.
Providing a Preference Interface
For user-facing preferences, Table 1-1 lists the options for displaying those preferences to the user. As you can see from this table, most options involve the creation of a custom user interface for managing and presenting preferences. If you are creating an iOS app, you can use a Settings bundle to present preferences, but you should do so only for settings the user changes infrequently.
Note: An example of preferences that might change frequently include things like the volume levels or control options of a game. An example of preferences that might change infrequently are the email address and server settings in the Mail app. For iOS apps, it is ultimately up to you to decide whether it is appropriate to expose preferences from the Settings app or from inside your app.
Preferences in Mac apps should be accessible from a Preferences menu item in the app menu. Cocoa apps created using the Xcode templates provide such a menu item for you automatically. It is your responsibility to present an appropriate user interface when the user chooses this menu item. You can provide that user interface by defining an action method in your app delegate that displays a custom preferences window and connecting that action method to the menu item in Interface Builder.
There is no standard way to display custom preferences from inside an iOS app. You can integrate preferences in many ways, including using a separate tab in a tab-bar interface or using a custom button from one of your app’s screens. Preferences should generally be presented using a distinct view controller so that changes in preferences can be recorded when that view controller is dismissed by the user.
The Organization of Preferences
Preferences are grouped into domains, each of which has a name and a specific usage. For example, there’s a domain for app-specific preferences and another for systemwide preferences that apply to all apps. All preferences are stored and accessed on a per-user basis. There is no support for sharing preferences between users.
Each preference has three components:
The lifetime of a preference depends on which domain you store it in. Some domains store preferences persistently by writing them to the user’s defaults database. Such preferences continue to exist from one app launch to the next. Other domains store preferences in a more volatile way, preserving preference values only for the life of the corresponding user defaults object.
A search for the value of a given preference proceeds through the domains in an
NSUserDefaults object’s search list. Only domains in the search list are searched and they are searched in the order shown in Table 1-2, starting with the NSArgumentDomain domain. A search ends when a preference with the specified name is found. If multiple domains contain the same preference, the value is taken from the domain nearest the beginning of the search list.
The Argument Domain
The argument domain comprises values set from command- line arguments (if you started the app from the command line) and is identified by the
NSArgumentDomain constant. Values set from the command line are automatically placed into this domain by the system. To add a value to this domain, specify the preference name on the command line (preceded with a hyphen) and follow it with the corresponding value. For example, the following command launches Xcode and sets the value of its IndexOnOpen preference to NO :
Preferences set from the command line temporarily override the established values stored in the user’s defaults database. In the preceding example, setting the
IndexOnOpen preference to NO prevents Xcode from indexing projects automatically, even if the preference is set to YES in the user defaults database.
The Application Domain
The application domain contains app-specific preferences that are stored in the user defaults database of the current user. When you use the shared
NSUserDefaults object (or a NSUserDefaultsController object in OS X) to write preferences, those preferences are automatically placed in this domain.
Because this domain is app-specific, the contents of the domain are tied to your app’s bundle identifier. The contents of this domain are stored in a file that is managed by the system. Currently, this file is located in the $HOME
/Library/Preferences/ directory, where $HOME is either the app’s home directory or the user’s home directory (depending on the platform and whether your app is in a sandbox). The name of the user defaults database file is <ApplicationBundleIdentifer>.plist , where <ApplicationBundleIdentifer> is your app’s bundle identifier. You should not modify this file directly but can inspect it during debugging to make sure preference values are being written by your app.
The Global Domain
The global domain contains preferences that are applicable to all apps and is identified by the
NSGlobalDomain constant. This domain is typically used by system frameworks to store system-wide values and should not be used by your app to store app-specific values. If you want to change the value of a preference in the global domain, write that same preference to the application domain with the new value.
Examples of how the system frameworks use this domain:
The Languages Domains
For each language in the
AppleLanguages preference, the system records language-specific preference values in a domain whose name is based on the language name. Each language-specific domain contains preferences for the corresponding locale. Many classes in the Foundation framework (such as the NSDate , NSDateFormatter , NSTimeZone , NSString , and NSScanner classes) use this locale information to modify their behavior. For example, when you request a string representation of an NSCalendarDate object, the NSCalendarDate object uses the locale information to find the names of months and the days of the week for the user’s preferred language.
The Registration Domain
The registration domain defines the set of default values to use if a given preference is not set explicitly in one of the other domains. At launch time, an app can call the
registerDefaults: method of NSUserDefaults to specify a default set of values for important preferences. When an app launches for the first time, most preferences have no values, so retrieving them would yield undefined results. Registering a set of default values ensures that your app always has a known good set of values to operate on.
The contents of the registration domain can be set only by using the
registerDefaults: method.
Viewing Preferences Using the Defaults Tool
In OS X, the
defaults command-line tool provides a way for you to examine the contents of the user defaults database. During app development, you might use this tool to validate the preferences your app is writing to disk. To do that, you would use a command of the following form from the Terminal app:
defaults read <application-bundle-identifier>
To read the contents of the global domain, you would use the following command:
defaults read NSGlobalDomain
For more information about using the defaults tool to read and write preference values, see defaults man page.
Copyright © 2013 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2013-10-22
Make things happen quickly without touching the mouse
This tutorial describes how to make use of the macOS Terminal to make your life easier and less frustrating.
What Apple calls the Terminal is what Linux people call the shell console (more specifically, the Bash shell). It’s also called a command-line terminal, abbreviated as CLI.
Information here is often used in interview questions.
Open Terminal (several ways)
On the Mac, the Terminal app is kinda buried, probably perhaps because those who use a MacOS laptop just for social media probably won’t need a Terminal.
But if you’re a developer, it’s hard to get away from using a CLI.
There are different ways to open a Terminal command line.
My preferrence is a way that doesn’t require reaching for a mouse and using the least number of keystrokes:
Alternately, if you prefer moving your mouse:
PROTIP: If you are at the Finder program (since Yosemite) you can open a Terminal to a folder listed within Finder by pointing your mouse on it, then tapping with two fingers on the touchpad/mousepad.To enable that:
Bash shell invocations
I put in an echo in the various files that macOS executes upon user login, when a new terminal is opened, and when a bash shell is invoked:
When macOS logs in a user, it executes file /etc/profile. That file’s code:
echo ${BASH-no} resolves to /usr/local/bin/bash.
The /etc/bashrc file contains:
The above defines the $PS1 variable which sets the Terminal’s prompt to the left of the cursor.
NOTE: On Ubuntu, instead of /etc/bashrc, the file is /etc/bash.bashrc.
RedHat also executes /etc/profile.d if the shell invoked is an “Interactive Shell” (aka Login Shell) where a user can interact with the shell, i.e. your Terminal bash prompt.
Thus, whatever is specified in /etc/profile is NOT invoked for “non-interactive” shells invoked when a user cannot manually interact with it, i.e. a Bash script execution.
PROTIP: One can change those files, but since operating system version upgrades can replace them without notice, it’s better to create a file that is not supplied by the vendor, and within each user’s $HOME folder: ~/.bash_profile
In other words, file /etc/profile is the system wide version of ~/.bash_profile for all users.
Examples of custom settings include:
export HISTSIZE=1000 # sets the size of .bash_history lines of command history (500 by default)
User Mask for permissions
Wikipedia says umask controls how file permissions are set for newly created files. Please read it for the whole story on this.
Within Text Editors/IDEs
Many prefer the terminals built into VS Code and other editors/IDEs.
Text wrapping
This page contains notes for system administrators and developers,who need to control Macs below the UI level, which requiretyping commands into a command-line terminal screen.
Hyper terminal app
Get the .dmg installer from the websitehttps://hyper.is. It’s used by tutorials author Wes Bos.
Unlike Apple’s Terminal, which is closed-source, Hyper is an open-source and extensible terminal emulator. It is available on MacOS, Windows, and Linux because it’s built using Electron (the same platform that powers Atom, Slack, and Brave). So it can be slow.
To customize Hyper, add the name of many packages to its config file ~/.hyper.js. Build an extension based on hyper.is/#extensions-api.
iTerm2 for split pane
Many prefer to install and use iTerm2 instead of the built-in Terminal program.Install iTerm2 using Homebrew:
Terminal does not support but iTerm2 does support dividing the CLI into several rectangular “panes”, each of which is a different terminal session:
Pressing the shortcut again restores the hidden panes.
On Linux, there is the
screen command.
See Iterm2 Cheat Sheet of iTerm2 keyboard shortcuts. https://github.com/nobitagit/iterm-cheat-sheet/blob/master/README.md
Alphabetical Commands list
A list of all commands native to macOS is listed alphabetically at https://ss64.com/osx.
Exit
To exit from the Terminal shell:
exit
Get back in for the remainder of this tutorial.
Shutdown
CAUTION: To kill all apps and shutdown a Mac right away (with no warning and no dialog):
sudo shutdown -h now
Text Command Line Bash Shortcuts
These come from the bash terminal on Linux machines here: Press control with your pinkie, then …
Environment Variables
A big reason to use a command-line terminal is to set environment variables.
Like on PCs, the PATH system environment variable storeswhere the operating system should look to find a particular program to execute.
Default editor
Command history
Foreground processes and background jobs
Folders accessed by developers
Terminal File Listing Home Folder
By default, the Terminal shows the hard drive and lowest level file folder name, in white letters over black.
Show Hidden Invisible Files in Finder
By default, the Mac’s Finder does not show hidden files.
For more on this, see this.
Create Terminal AliasesWireless up and down
Most developers leave files un-hidden.
tree alias or brew install
OSX does not come with the tree command that many other Linux distributions provide. So add it using:
If you don’t want to install a program, add an alias for a tree command by adding this in the ~/.bash_profile script:
Alternately, add it by installing a command using brew:
Active Terminal sessions need to be closed so new Terminal | Shell | New Window | Shell has this activated.
See list of parameters:
List only 2 levels deep with human-readable file size kilobytes and sort by last modified date:
Cursor to Screen Hot Corners
By default, if you move the mouse to one of the corners of the screen,stuff happens. It can be annoying.
Hosts fileReset App Preferences Meaning
Mac, Windows, and Linux systems have a hosts file that locally does the work of the public DNS– translating host names (typed on browser address field) to IP address numbers.
Terminal Ping Host
Find the IP address of a website host name:
SSH tunnel
To access a remote server through a port that is not open to the public:
DNS Configuration with NameBench
Analysis at one time showed this ranking by speed:
Google Namebench tries the speed of various DNS servers from YOUR machine (which takes some time) and pops up in your browser this:
An example:
Clear DNS Cache
Different commands are needed for different versions of OS.OSX 10.10 added requirement for sudo when using the built-in discoveryutil:
sudo discoveryutil udnsflushcaches
Bash Profile Configuration
The profile file is run during boot-upto configure the terminal to define file path, shims, and autocompletion handlers.
This is the single biggest frustration with people using Linux on Mac.
One of the earliest articles on bash hereshows shell variables, environment variables, and aliases.
Each operating system has its own file name for its profile:
PROTIP: If there is both a .bash_profile and a .profile file, boot-up only executes the first one it finds.
According to the bash man page, .bash_profile is executed during login before the command prompt,while .bashrc is executed for interactive non-login shells such aswhen you start a new bash instance by typing /bin/bash in a terminal.
Here’s what my profile file begins:
https://github.com/gcuisinier/jenv/blob/master/README.md
Operating System Kernel
I can use Linux commands in my version of the operating system:
![]()
uname -a (a for all) or uname -rvm
returns:
14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
which is a combination of:
uname -r for release number,
uname -v for kernel version, uname -m for model:
x86_64 for Intel or AMD 64-bit or
i*86 for 32-bit.
For more information about Darwin operating systemdeveloped at Apple, see:
NOTE: lsb_release -awhich works on Debian, RHEL 6.6, and Ubuntu is not recognized on Gentoo nor CentOS 6,which has no folder /etc/lsb-release.
See Distriwatch.com,which describes releases of different Linux distributions.
Setup Your Mac Like a Pro
Paul Irish is one of top pros among developers, and now a Google Evangelist.He put his Mac configuration settings ongithub.com/paulirish/dotfiles. But he recommends cloning github.com/mathiasbynens/dotfiles/.
On the Git page notice that he has established an industry convention of usingProjects folder we defined earlier.
On the Git page I clicked on Clone in Desktop.
The library is called dotfiles because that’s what hidden files are called,and most configuration files are hidden.
PS1 terminal prompt setting
Paul Irish offers his setup-a-new-machine.sh athttps://github.com/paulirish/dotfilesZShell (included with Mac and can be set as the default in Terminal)* oh-my-zsh as a ZShell framework* The oh-my-zsh Git plugin* And the oh-my-zsh theme called jnrowe</p>
By default, if you have a long file name, it would leave little room to type in commands before it wraps to the next line.
To redefine what appears in the prompt,edit this file using the vi editor that comes with each Mac:vi .bashrc Copy this and paste to the bottom of the .bashrc file:
The command above uses global parameters $USER and $PWD,plus colors from this list.
Root user for sudo commands
If you try a command that responds about “permissions denied”, you need to execute as a root user.
The root user has the ability to relocate or remove required system files and to introduce new files in locations that are protected from other users. A root user has the ability to access other users’ files.
Any user with an administrator account can become the root user or reset the root password.
Under a *nix system like MacOS you must have “root” (administrative) privileges to start IP-services using ports smaller than 1024.
After MacOS install, the root or superuser account is not enabled. While it is possible to enable the root account, once enabled, if forgetten, you’ll have to reboot from the installer drive (a hassle).
PROTIP: There are several ways to invoke sudo*
PATH
NOTE: The folders that bash looks into are in bin:
/bin/echo $PATH
On a fresh Yosemite, that would contain:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Each additional app adds to the front of the list:
/Library/Frameworks/Python.framework/Versions/3.4/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Separating the folders between colon separator:
New folders are added to the front of the PATH using a command such as:
export PATH=<new folders>:$PATH
Depending on how you’re setup, file ~/.profile or ~/.bash_profile or ~/.bash_login contains the path echo’d.
Or your PATH may be set in /etc/profile for all users
Create Windows-like shortcuts with parameters using text editor
http://www.jesseweb.com/coding/automator/create-windows-like-shortcuts-with-parameters/
Mac OSX doesn’t allow you to create shortcuts like Windows.OSX alias don’t allow parameters (ex. create a Screen Sharing shortcut that connects to a specific computer).
Jessie suggests this to create a Windows like shortcut with parameters in the Comments field.
Another alternativeis to use a text editor to create URL shortcut fileslike the ones Windows Internet Explorer stores its bookmarks. Apple Safari recognizes them when clicked within Finder.So they are cross-platform.
Mount .dmg files using hdiutil tool
Reset App Preferences In Mac Terminal 1IPv6 compatibility with Curl command line apps
curl http://localhost:3000
Previously, when invoked on Mac OS 10.10 (Yosemite), you needed to add a parameter to make the request use IPv4:
curl http://localhost:3000 –ipv4
Otherwise, even if the URL loads fine in a browser, you will see an error message such as:
curl: (7) Failed to connect to localhost port 3000: Connection refused
This occurs because curl, under Yosemite, uses IPv6 by default but some apps, such as LoopBack.io, by default uses IP v4.
See if you see IP v6 entries in your hosts file (::1 localhost, fe80::1%lo0 localhost). If they are there it is likely that curl is making requests using IP v6.
You can make your LoopBack app use IPv6 by specifying an IPv6 address as shown below:
Largest files taking up disk space
Linux has a ncdu (NCurses Disk Usage) utility to list files in order of how much space they occupied.
Empty Trash
When files or folders are moved to Trash, they are sent to folder
~/.Trash .
To recover disk space taken up by files which have been moved to Trash, there are several ways:
Ulimit Too Many Files
By default, operating systems limit how many file descriptors to allow.Each operating system version has a different approach.
Linux operating systems have this command:
ulimit -a
On my Sierra the response was:
PROTIP:
launchctl is a rough equivalent to the systemctl command used in Linux systems.launchctl interfaces with launchd to load, unload daemons/agents and generally control launchd.
Disable System Integrity Protection
Some programs make calls to the operating system which OSX began to see as a threat, beginning with El Capitan.
Apple says System Integrity Protection blocks code injection (and many other things).
But what about useful programs (such as XtraFinder)which works by injecting its code into Finder and other application processes?
To get around this, you need to partially disable System Integrity Protection in OS X El Capitan.See Apple’s article on how:
Reset App Preferences Android
Skill Certification
Video course Mac OS X Support: Installation and Configureis the first of courses on Plurasight towardApple Certified Support Professional (ACSP)
Dotfile Settings from others
Daemons and Agents
Resources:
[2] VIDEO
[3] Advanced Bash-Scripting Guide by Mendel Cooper 2012
Reset App Preferences In Mac Terminal 10
[4] CommandLineFu.com
Reset App Preferences In Mac Terminal 4
https://zwischenzugs.com/2018/01/06/ten-things-i-wish-id-known-about-bash/https://leanpub.com/learnbashthehardway
https://blog.flowblok.id.au/2013-02/shell-startup-scripts.htmlhttps://bitbucket.org/flowblok/shell-startup/src/default/
https://linuxaria.com/howto/7-hidden-features-of-bash
![]() More on OSX
This is one of a series on Mac OSX:
Please enable JavaScript to view the comments powered by Disqus.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |