MDKwiki 🍂

main page, file list (906), stats, random article

# Mac

The Mac, short for Macintosh (Q75687 on Wikidata), is a brand of computer that has been continuously released by Apple. Although not as popular as Microsoft's Windows line of operating systems, Mac is certainly no underdog.

# Sleep behaviour

Last updated February 2021

Sometimes you need your Mac to stay awake to complete a long task like compiling or transferring data.

Screen off, still running

Keyboard shortcut to lock your Mac, turn off the screen, and continue running:

⌘ + control + q

Screen on, still running

This command won't let your Mac sleep until you control + c the terminal. Open a terminal and type:

caffeinate -disu

# Keeping track of launch agents

Last updated February 2021

Launch agents/daemons are scripts that tell the system to run executables at user login. These are mostly background daemons such as software updaters and are mostly harmless. They are placed in the following locations:

Despite all the protections in modern macOS, apps can still freely place launch agents as they desire without any prompt from the user. My biggest frustration comes from Adobe, which insists on launching a background Creative Cloud updater that spawns half a dozen other processes.

Clean-up Script

I have written a script called agentlookout that when ran cleans up your launch agents/daemons and removes ones not whitelisted. It's a very simple script that I recommend running once in a while and especially after launching Chrome and any Adobe products. I wouldn't recommend automating this process so that you can catch any launch agents; you don't mind sticking around as you accumulate more apps on your Mac.

When ran it looks like this:

Will delete unrecognized launch agents: - /Users/harry/Library/LaunchAgents/com.adobe.GC.Invoker-1.0.plist - /Users/harry/Library/LaunchAgents/com.google.keystone.agent.plist - /Users/harry/Library/LaunchAgents/com.google.keystone.xpcservice.plist Delete? [y/n]

Code

#!/bin/bash # Launch agents that won't be deleted ALLOWED_LAUNCH_AGENTS=("com.dropbox.DropboxMacUpdate.agent.plist" "com.tapbots.Pastebot.PasteService.plist") delete=() shopt -s nullglob launch_agent_check() { for f in $1; do filename=$(basename "$f") if [[ ! " ${ALLOWED_LAUNCH_AGENTS[@]} " =~ " ${filename} " ]]; then delete+=("$f") fi done } launch_agent_check "/Library/LaunchAgents/*.plist" launch_agent_check "/Library/LaunchDaemons/*.plist" launch_agent_check "$HOME/Library/LaunchAgents/*.plist" if [ "${#delete[@]}" -eq 0 ]; then echo "No launch agents found, exiting..." exit 0 fi echo "Will delete unrecognized launch agents:" for f in ${delete[@]}; do echo " - $f" done delete_agents() { sudo rm "${delete[@]}" } while true; do read -p "Delete? [y/n] " yn case $yn in [Yy]* ) delete_agents; break;; [Nn]* ) exit;; * ) echo "Please answer yes/no";; esac done

# Delete .DS_Store

Last updated February 2021

.DS_Store is a file on Mac that Finder places within directories in order to store directory-specific preferences. It serves a purpose and is mostly harmless, but sometimes you need to delete all of them within a directory. This is a quick one liner to do that:

find . -name «.DS_Store» -type f -delete

For a more permanent and reliable solution, try excluding .DS_Store with the tool you are using to archive or transfer files.

# Reset Launchpad layout

Last updated February 2021

Launchpad gets messy; this command resets the layout. You may need to open Launchpad two times before all icons display again. Enter in a terminal:

defaults write com.apple.dock ResetLaunchPad -bool true && killall Dock

# Running macOS as a VM guest with VirtualBox

Last updated February 2021

This has been tested on OS X Snow Leopard.

  1. Confirm that EFI is enabled in the VM settings; if you select the default OS X template within VirtualBox, then this will already be configured.

  2. Enter the following commands in your terminal:

    VBoxManage modifyvm «Mac» –cpuidset 00000001 000106e5 00100800 0098e3fd bfebfbff VBoxManage modifyvm «Mac» –cpu-profile «Intel Core i7-6700K» VBoxManage setextradata «Mac» «VBoxInternal/Devices/efi/0/Config/DmiSystemProduct» «iMac11,3» VBoxManage setextradata «Mac» «VBoxInternal/Devices/efi/0/Config/DmiSystemVersion» «1.0» VBoxManage setextradata «Mac» «VBoxInternal/Devices/efi/0/Config/DmiBoardProduct» «Iloveapple» VBoxManage setextradata «Mac» «VBoxInternal/Devices/smc/0/Config/DeviceKey» «ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc» VBoxManage setextradata «Mac» «VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC» 1

  3. Boot the VM and you should be loaded into the EFI shell.

  4. Type exit in the shell.

  5. Choose Boot Maintenance Manager, then Boot From File.

  6. Select the entry listing HFS+, then navigate through the file hierarchy like so: System/Library/CoreServices/boot.efi.

  7. Once you've found boot.efi, press return to boot the installer.

# Problems

# Sources

# Server: Starting and stopping launch daemons

Last updated February 2021

Launch daemons are script files that are managed by the system that have versatile options for running them; the system tracks «loaded» daemons as to avoid running duplicates. They are located at /Library/LaunchDaemons/.

Starting (run as root)

launchctl load /Library/LaunchDaemons/com.example.daemon.plist

Stopping (run as root)

launchctl unload /Library/LaunchDaemons/com.example.daemon.plist

# Server: Writing launch daemons

Last updated February 2021

General information such as what launch daemons are and how to manage them can be found at Mac Launch Daemons.

# Example Skeleton

/Library/LaunchDaemons/com.webserver.daemon.plist

<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd > Label com.webserver.daemon ProgramArguments /Users/_webserver/website/webserver –port 3000 EnvironmentVariables PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin RunAtLoad WorkingDirectory /Users/_webserver/website UserName _webserver StandardOutPath /var/log/webserver/stdout.log StandardErrorPath /var/log/webserver/stderr.log

# Explainer

# Logging

StandardOutPath and StandardErrorPath are both optional. NOTE: It is necessary to create the subdirectory under /var/log, e.g. mkdir -p /var/log/webserver.

# Server: Creating daemon users

Last updated February 2021

Daemon users are usually used alongside launch daemons. Find out what they are and how to create them.

In this example a daemon user named _webserver is created. Make sure you replace this with your own new daemon username.

  1. Decide on a name for your user and prefix it with an underscore; this will also be the name for a new group the user will be a member of. For example, _webserver.

  2. In a terminal, enter interactive user mode:

    $ sudo dscl Entering interactive mode... (type «help» for commands)

  3. Move to the base folder:

    > cd /Local/Default/

  4. List all groups and find an unused GID, preferably less than 500:

    /Local/Default > ls Groups gid

  5. Create a group and assign the GID found in the previous step. In this example, the GID found is 300, but it may differ for you:

    /Local/Default > create Groups/_webserver /Local/Default > create Groups/_webserver PrimaryGroupID 300

  6. List all users and find an unused UID, preferably less than 500; this can be different from your GID:

    /Local/Default > ls Users uid

  7. Create a user and assign the UID found in the previous step. In this example, the UID found is 300, but it may differ for you:

    /Local/Default > create Users/_webserver UserShell /bin/bash /Local/Default > create Users/_webserver UniqueID 300

  8. Set the user's group ID to the GID previously found and assigned to the group; alongside this, also set the user's home directory:

    /Local/Default > create Users/_webserver PrimaryGroupID 300 /Local/Default > create Users/_webserver NFSHomeDirectory /Users/_webserver

  9. Add the user to the previously created group:

    /Local/Default > append Groups/_webserver GroupMembership _webserver

  10. Exit out of interactive user mode:

/Local/Default > exit
Goodbye
  1. Run these two commands to remove the user from the user-facing login screen:
sudo dscl . delete /Users/\_webserver AuthenticationAuthority
sudo dscl . create /Users/\_webserver Password "\*"
  1. Create the user's home directory and set the correct permissions:
sudo mkdir /Users/\_webserver
sudo chown \_webserver:\_webserver /Users/\_webserver
  1. This user is now created and can be used within launch daemons.

Instructions distilled from a similar document in the Minecraft Wiki

# Server: Nginx configuration file location

Last updated February 2021

With a standard Homebrew install, it is located at:

/usr/local/etc/nginx/nginx.conf

It has permissions of -rw-r--r-- USER:admin.

# Credits and Notes


This page was last edited on 2026-09-25 02:04:49.

All original text, code, images and content on the MDKwiki is CC0 1.0 - we have a Git and an RSS feed that can be followed.

Let there be peace on Earth.

★

τ