Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
OSX CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings
Contents
An OS X CLI for programmatically opening a new terminal tab/window in the standard terminal application, Terminal.app
, optionally with a command to execute and/or a specific title and specific display settings.
Important: Irrespective of installation method, ttab
needs to be granted access for assistive devices in order to operate, which is a one-time operation that requires administrative privileges.
If you're not prompted on first run and get an error message instead, go to System Preferences > Security & Privacy
, tab Privacy
, select Accessibility
, unlock, and make sure Terminal.app
is in the list on the right and has a checkmark.
For more information, see Apple's support article on the subject
With Node.js or io.js installed, install from the npm registry:
[sudo] npm install ttab -g
Note:
sudo
depends on how you installed Node.js / io.js and whether you've changed permissions later; if you get an EACCES
error, try again with sudo
.-g
ensures global installation and is needed to put ttab
in your system's $PATH
.bash
script as ttab
.chmod +x ttab
.$PATH
, such as /usr/local/bin
# Open a new tab in the current terminal window.
ttab
# Open a new tab in a new terminal window.
ttab -n
# Open a new tab and execute the specified command.
ttab ls -l "$HOME/Library/Application Support"
# Open a new tab, switch to the specified dir., then execute the specified command.
ttab -d ~/Library/Application\ Support ls -1
# Open a new tab with title 'How Green Was My Valley' and settings 'Grass'
ttab -t 'How Green Was My Valley' -s Grass
# Open a new tab and execute the specified script.
ttab /path/to/someScript
# Open a new tab, execute the specified script, then close the tab on termination.
ttab exec /path/to/someScript
# Open a new tab, execute a command, wait for a keypress, then close the tab.
ttab eval "ls \$HOME/Library/Application\ Support; echo Press a key to exit.; read -s -n 1; exit"
$ ttab --help
SYNOPSIS:
ttab [-w] [-s settings] [-t title] [-g|-G] [-d dir] [command [param1 ...]]
DESCRIPTION:
Opens a new Terminal.app tab and optionally executes a
command and assigns settings, among other options.
IMPORTANT: *Terminal.app must be allowed assistive access* in order for this
utility to work, which requires one-time authorization with administrative
privileges. If you get error messages instead of being prompted, authorize
Terminal.app via System Preferences > Security & Privacy > Privacy >
Accessibility.
The new tab will run a login shell (i.e., load the user's shell profile)
and by default inherit the working directory from the parent shell.
-w
creates the new tab in a new window rather than in Terminal's front
window.
-s
specifies the settings (profiles) to apply to the new tab, as
defined in Terminal.app's Preferences > Profiles, such as 'Grass';
settings determine the appearance and behavior of the new tab; name
matching is case-insensitive.
-t
specifies a custom title to assign to the new tab; otherwise, if a
command is specified, its first token will become the new tab's title.
-d
explicitly specifies a working directory for the new tab; by default, the
invoking shell's working directory is inherited (even if -w is also
specified).
-g
(back*g*round) causes Terminal not to activate, if it isn't the frontmost
application); within Terminal, however, the new tab will become active
active tab; useful in scripts that launch other applications and
don't want Terminal to steal focus later.
-G
causes Terminal not to activate *and* the active element within Terminal
not to change; i.e., the active window and tab stay the same. If Terminal
happens to be fronmost, the new tab will effectively open in the
background.
NOTE: With -g or -G specified, for technical reasons, Terminal / the new
tab will still activate *briefly, temporarily* in most scenarios.
Quoted parameters are handled properly and there's no need to quote the
command as a whole, provided it is a *single* command.
Prefix such a single command with 'exec' to automatically close the tab
when the command terminates, assuming the tab's settings are configured to
close the tab on termination of the shell.
To specify *multiple* commands, use 'eval' followed by a single,
*double*-quoted string in which the commands are separated by ';' Do NOT
use backslash-escaped double quotes *inside this string*; rather, use
*single-character backslash-escaping* as needed. Use 'exit' as the last
command to automatically close the tab when the command terminates,
assuming the tab's settings are configured to close the tab on termination
of the shell.
Precede 'exit' with 'read -s -n 1' to wait for a keystroke first.
EXAMPLES:
# Create new tab with title 'Green' using settings 'Grass'
ttab -t Green -s Grass
ttab ls -l "$HOME/Library/Application Support"
ttab -d "$HOME/Library/Application Support" ls -1
ttab /path/to/someScript arg1 arg2
# Execute a script and close the tab on termination (settings permitting).
ttab exec /path/to/someScript arg1 arg2
# Pass a multi-command string via 'eval', wait for keystroke, then exit.
ttab eval "ls \$HOME/Library/Application\ Support;
echo Press a key to exit.; read -s -n 1; exit"
Copyright (c) 2015 Michael Klement mklement0@gmail.com (http://same2u.net), released under the MIT license.
This project gratefully depends on the following open-source components, according to the terms of their respective licenses.
npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D)
denotes a development-time-only dependency, (O)
an optional dependency, and (P)
a peer dependency.
Versioning complies with semantic versioning (semver).
v0.1.6 (2015-06-01):
v0.1.5 (2015-06-01):
v0.1.4 (2015-06-01):
package.json
.make browse
now opens the GitHub repo in the default browser.v0.1.3 (2015-06-01):
v0.1.2 (2015-06-01):
v0.1.1 (2015-06-01):
v0.1.0 (2015-06-01):
FAQs
OSX CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings
The npm package ttab receives a total of 4,112 weekly downloads. As such, ttab popularity was classified as popular.
We found that ttab demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.