Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tirwit

macrumors newbie
Original poster
Jan 20, 2010
28
0
Hi

I have seen some people opening apps (like Safari) from the Terminal jut by typing:

Code:
safari

But for me to do so, I have to do:

Code:
open -a safari

I know it's not important but it's a time saver -> What do I need to do to not have to type "open -a" to open a application?

Thanks :)
 
I don't know of any way to open an application by only typing its name. The only solution I would have is to make a symbolic link of the executable <app_path>/Contents/MacOS/<app_name> and place it in some directory that you add to the PATH variable.

I often use Spotlight to open apps if I don't want to switch to the finder or browse through the application directory (or wherever the app is located).

Edit: You could also create an alias so that you can type
Code:
o safari
You still have to type 2 additional characters, but it's better than open -a.
 
You can make a shell script and put it in /usr/local/bin.

#!/bin/sh
open -a Safari

Call it 'safari' then give it permissions to execute (i forgot the safest permissions for this).
 
You can make a shell script and put it in /usr/local/bin.

#!/bin/sh
open -a Safari

Call it 'safari' then give it permissions to execute (i forgot the safest permissions for this).

- What does the "#!" means?

- Can I create the script using AppleScript Editor (never used this program before)?
 
This isn't AppleScript

Given that you don't seem to know the most basic things about the shell I suggest you go and do some reading. Perhaps start with this http://aplawrence.com/MacOSX/macosxshell.html

Ok, thanks. I'll try it. It's very difficult for me since I don't have almost any programming teaching in college (3rd year physics engineering only gave me a very very basic introduction to C), but I'll go for it. :)
 
You can make a shell script and put it in /usr/local/bin.

#!/bin/sh
open -a Safari

Call it 'safari' then give it permissions to execute (i forgot the safest permissions for this).

Or define an alias in the shell. The syntax differs between 'bash' and 'tcsh'.

Bash:
Code:
alias safari='open -a Safari.app'

Add it to your shell profile and it will be ready for use.
 
Or as I suggested in my first reply just add /Applications/Safari.app/Contents/MacOS/ to your PATH environment variable. This contains the actual Safari executable:

Code:
ls -l /Applications/Safari.app/Contents/MacOS/
total 10528
-rwxr-xr-x  1 root  wheel  13489168  7 Jun 01:12 Safari
 
Or as I suggested in my first reply just add /Applications/Safari.app/Contents/MacOS/ to your PATH environment variable.

Doing it that way has some undesirable side-effects.

First, if the app is already open, another copy is launched. Second, the app is a child of the shell, and the shell will wait for it to terminate. Third, command-line args are not properly delivered to the app for opening. Fourth, the app can misbehave: when I tried it, it didn't show a menubar on some older OS versions.
 
I keep my main apps on the dock I only use terminal to open things when I do some serious work (witch is not alot). So open -a is fine, there are many good sugestions here so try them I fought of one but they beat me to it. So good luck.
 
Problem solved. A friend of mine created the .bash_profile (which I thought I didn't need since I had .bashrc) and it was solved. Thanks anyway :)
 
Here's my .bash_profile and .bashrc if you want something else to play with.

I've removed some sensitive info from my bashrc, but it's mostly intact. There are a number of very handy aliases for common commands (e.g. ll for ls -l, la instead of ls -a, bye instead of exit or logout). Also, by editing the value in quotes next to PS1 you can have the prompt display whatever name you like. Be sure to un comment it before you save.

The profile offers some handy features like color coding. Put these in a plain text file and rename each one to put a "." in front of the name, and place them in your home folder. Exit the shell and restart it, and you should see the effects.

Feel free to edit them to your needs!

.bashrc

Code:
# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific aliases and functions

alias a=alias
alias la='ls -a'
alias ll='ls -lt'
alias ls='echo $PWD; ls'

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ps='ps -aux'
alias du='du -h'
alias df='df -h'
alias bye='logout'

alias ssh='ssh -Y'

# Reset the prompt
# Directory:
# PS1='[\w]$ '
# Hostname:
#PS1='whateveryouwant$ '

Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# BASH
export BASH_ENV=$HOME/.bashrc
export USERNAME=""

# Set DISPLAY
export DISPLAY=:0.0

# My Paths
export PATH=$PATH:$HOME/bin:./

# PREFIX
export PREFIX=/usr/local

# Terminal colors
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.