Important file and folder locations

Automator workflows These are the possible places to you place your workflow files created by automator. For example services with which you can add custom actions to the file / folder context menu in finder etc.
  • ~/Library/Services
  • /Library/Services
  • /System/Library/Services)
macOS 10.1x

Misc Tips & Tricks

In terminal write one of the following commands:
  • source ~/.bash_profile
  • or
  • . ~/.bash_profile
Proceed as follows
  1. Double-click Terminal. Or type terminal in spotlight and press return
  2. type sudo nano /etc/hosts in terminal then hit return. You'll be asked for your password. Enter your password
  3. Edit the hosts file as you need. I.e. enter a new line or edit a existing one
  4. Press Ctrl+O to save. You'll be asked to check the save file name, just press return
  5. Press Ctrl+X to exit nano
In terminal execute
zip -r foo.zip directory2zip -x "*.DS_Store"
In terminal execute
sudo vi ~/.bash_profile
Then add the following to ~/.bash_profile
alias lsa="ls -al"
This adds an alias named lsa to the bash session which executes the command ls -al

Show hidden files and folders

In terminal execute
defaults write com.apple.finder AppleShowAllFiles YES ; killall Finder

Hide hidden files and folders

In terminal execute
defaults write com.apple.finder AppleShowAllFiles NO ; killall Finder

Global (in /etc/paths.d)

Add new text file to /etc/paths.d (i.e. java). You can do this in terminal like this
cd /etc/paths.d
sudo vi java
Then add the location to the new text file and save it.
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin
To enable this PATH you need to reboot the system

For shell (in ~/.bash_profile)

Edit the ~/.bash_profile in your user profile (this file is hidden by default)
sudo vi ~/.bash_profile
Add the location to the ~/.bash_profile and export it
#i.e. add JAVA bin to PATH
export PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

#or set JAVA_HOME variable
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

Compare two directories with DIFF

Use diff command to compare. You can do this in the terminal like this
diff -ruN orig/ new/ > file.patch
# -r == recursive, so do subdirectories
# -u == unified style, if your system lacks it or if recipient
#       may not have it, use "-c"
# -N == treat absent files as empty

Update directories with PATCH

Use patch command to update. You can do this in the terminal like this
patch -s -p0 < file.patch
# -s == silent except errors
# -p0 == needed to find the proper folder

Create public and private SSH keys

First thing that you need to do on your OSX machine is to create a directory that will store your SSH keys. Then you will generate a public and private key for your account, launch the Terminal and punch in some commands: Create a .ssh Directory Change to the home directory
cd ~/
Create a SSH directory name .ssh and move into it
mkdir .ssh ; cd .ssh
Make sure that the file permissions are set to read/write/execute only for the user
chmod go-rwx .ssh
Create your private and public key, the blank quotes at the end of the command gives the private key no password, so allowing for passwordless logins!
ssh-keygen -b 1024 -t rsa -f id_rsa -P ""

keygen-generate-ssh-keys Change into the .ssh directory and list the contents of that .ssh directory
cd .ssh ; ls -la
 -rw-------   1 username  staff   887B Jun  1 11:35 id_rsa 
 -rw-r--r--   1 username  staff   239B Jun  1 11:35 id_rsa.pub
Thats your SSH keys created, the private key is the id_rsa and the public one is the id_rsa.pub, don’t give out the private one always keep that one only on your local machine. Sharing the Public Key Create an authorized_keys in the .ssh directory of the remote computer that you want to connect to. touch authorized_keys You can create automatic logins by adding the contents of your public key to the  authorized_keys file on the remote device. To see and copy your public key use the cat command and copy the contents:
cat id_rsa.pub
ssh-rsa  AAAAB3NzaC1yc2EAAAABIwAAAIEA2CtcmYRmQJX04pZnrTPrU68BZMk9YlbI6CUcFUp
RVw29p V7mxW16wd/q9z7n+xytqdp4wsAc/7+24ZVikMhhRetEGr3LSBz5gm9980oTPEy61+pDP2y
jafShe5xcszIUnQ rN1ohCuF7Y/a/TG6G6gaJGcLexUiwfTRtCAbpuzfU= This email address is being protected from spambots. You need JavaScript enabled to view it.
On the remote computer if needed, change the permssions on the authorized_keys file to write to add the public key, on a new line paste in your public key, and change permissions back to read only after for security. Allow write on authorised_keys
chmod u+w authorized_keys
Paste the entire id_rsa.pub content with vi or nano into the authorized_keys file, if using nano use the -w flag to not use incorrect line breaks. If the remote host does not have an “authorized_keys” file simply create one and after the public key is pasted in don’t forget to takeaway write permissions.
chmod u-w authorized_keys
Going Both Ways So now when you connect via SSH no password is prompted as the remote computer has your public key which is only decrypted by your private key held in your local .ssh/ directory. If you want the communications to be bilateral then repeat the process in the opposite order between the two. Now the two computers can securely connect with no password prompting, making it ideal to script between the two for file copies or back ups. Doing it Quicker Now instead of typing in
ssh This email address is being protected from spambots. You need JavaScript enabled to view it.
Make an alias in your bash shell you could alias it to
alias now='ssh This email address is being protected from spambots. You need JavaScript enabled to view it.'
Reload the the shell
source ~/.bash_profile
Then all you have to type in is the alias
now

Enable hidden "allow app installation from unidentified sources"

Execute in CLI
sudo spctl --master-disable

Stop macOS Siera from reopening applications upon startup

Execute in CLI
defaults write -g ApplePersistence -bool no

Stop Android File Transfer from popping up

  1. Kill all Android File Transfer (AFT) processes using Activity Monitor
  2. Remove AFT from your login items
  3. Remove the agent with the following terminal command:
    rm -r ~/Library/Application\ Support/Google/Android\ File\ Transfer/Android\ File\ Transfer\ Agent.app
    
  4. Rename the agents copy with:
    cd /Applications/Android\ File\ Transfer.app/Contents/Resources 
    mv Android\ File\ Transfer\ Agent.app Android\ File\ Transfer\Agent.app.disable

Create Windows (7) Installer USB disk on macOS X

Original article: https://superuser.com/questions/133152/creating-a-windows-7-usb-installation-disk-on-a-mac
Steps:
  1. Open a Terminal (under Utilities)
  2. Run diskutil list and determine the device node assigned to your flash media (e.g., /dev/disk2)
  3. asimophs-MacBook-Air:Pixar asimoph$ diskutil list
    /dev/disk0 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *251.0 GB   disk0
       1:                        EFI EFI                     209.7 MB   disk0s1
       2:                 Apple_APFS Container disk2         150.6 GB   disk0s2
       3:                  Apple_HFS Data                    74.2 GB    disk0s3
       4:                 Apple_APFS Container disk1         25.9 GB    disk0s4
    
    /dev/disk1 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +25.9 GB    disk1
                                     Physical Store disk0s4
       1:                APFS Volume Mojave                  19.8 GB    disk1s1
       2:                APFS Volume Preboot                 45.9 MB    disk1s2
       3:                APFS Volume Recovery                512.4 MB   disk1s3
       4:                APFS Volume VM                      2.1 GB     disk1s4
    
    /dev/disk2 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +150.6 GB   disk2
                                     Physical Store disk0s2
       1:                APFS Volume System                  127.1 GB   disk2s1
       2:                APFS Volume Preboot                 20.6 MB    disk2s2
       3:                APFS Volume Recovery                519.1 MB   disk2s3
       4:                APFS Volume VM                      1.1 GB     disk2s4
  4. Run diskutil unmountDisk /dev/diskN (replace N with the disk number from the last command; in the previous example, N would be 2) NOTE: Maybe you need to force the unmount command for the USB disk by adding the force parameter
  5. diskutil unmountDisk /dev/disk2
    or
    diskutil unmountDisk force /dev/disk2
    
  6. Execute sudo dd if=/path/to/downloaded.iso of=/dev/rdiskN bs=1m (replace /path/to/downloaded.iso with the path to where the image file is located; for example, ./windows7.iso)
  7. sudo dd if=/Volumes/System/Users/admin/Downloads/Windows7Installer.iso of=/dev/rdisk2 bs=1m
    
  8. Run diskutil eject /dev/diskN and remove your flash media when the command completes (this can take a few hours on slower drives)
  9. diskutil eject /dev/disk2
    
(Note: The sudo dd command executes for around 5 minutes, depends on the USB port and drive.)

See also