JavaScript
JavaScript is the second scripting language used for user interface scripting since Mac OS X 10.10, Yosemite. It’s the most common cross-platform scripting language mainly used for implementing features on websites and web-based applications. Using the script editor which is included in every copy of macOS is the standard way for running JavaScript for automation.
Some sample scripts
- Moving one folder to another
- AppleScript
123tell application "Finder"move folder someFolder to someOtherFolder replacing trueend tell
-
123test<div></div>
- JavaScript
1234var Finder = Application("Finder")Finder.move(someFolder,{to: <code>someOtherFolder,replacing:</code> true})
- AppleScript
Terminal commands and shell scripts
The terminal app provides a command-line interface to control your Mac using a set of commands. Using an admin account and password, you can tweak almost anything related to your system’s software code.
Use case – To install Xcode command line tools
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/sh # This script will install Command Line Tools for Xcode on a fresh installation of OS X. # Usage: curl https://raw.github.com/gist/3053979/install-command-line-tools-for-xcode.sh | sh DMG='command_line_tools_for_xcode_june_2012.dmg' cd $HOME/Downloads if [ ! -f ./$DMG ]; then echo 'Command Line Tools for Xcode not downloaded.' exit 1 fi hdiutil attach $DMG sudo installer -pkg '/Volumes/Command Line Tools/Command Line Tools.mpkg' -target / hdiutil detach "/Volumes/Command Line Tools" rm -i $DMG cd - echo 'Finished install Command Line Tools for Xcode' |
A shell is the command interpreter that provides ways to interact with the underlying operating system. The shell scans the command-line, analyzes it and determines what to do. Prior to Catalina, macOS came with Bourne again shell (bash) as the default user shell and also included other shells like the TENEX C shell (tcsh), the Korn shell (ksh), and the Z shell (zsh). In macOS 10.15 Catalina, bash has been replaced by zsh as the default login and interactive shell.