How can I launch Chrome with flags from command line more concisely? - macos

I am developing a WebGL driven application and I want to launch chrome like this from the command line:
open -a Google\ Chrome --args --disable-web-security
I just don't want to have to type that in every single time. Is there a way to easily turn that into a one word command? I am using a mac if it matters.

Just make an alias in your .bashrc or .bash_profile
alias ogc='open -a Google\ Chrome --args --disable-web-security'
And then reload your shell.
exec $SHELL
Now, every time you type ogc (or whatever you want to call it) in your terminal, it will run the full command open -a Google\ Chrome --args --disable-web-security

This work for me:
Modify the .bash_profile
Write this alias:
alias cchrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security'
Run
exec $SHELL
With the cchrome command open a new windows of chrome with the disable web security to solve the "access-control-allow-origin" problem

The Easiest way to Launch Chrome with flags in MAC using terminal is :
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --disable-features=CrossSiteDocumentBlockingAlways,CrossSiteDocumentBlockingIfIsolating
Any filter can come after -- in the above code --disable-features=CrossSiteDocumentBlockingAlways,CrossSiteDocumentBlockingIfIsolating is just an example.
Note: Make sure to close all instances of Chrome before running it.

Why not just run a webserver? Open a terminal and type
cd folder_with_html_and_assets
python -m SimpleHTTPServer
Now in your browser to go http://localhost:8000 When your done go to the terminal and press Ctrl-C
That seems much better than disabling your security and risking getting pwnd.

Related

OSX: Running multiple instances of an application with different arguments

I need to run multiple instances of Google Chrome but with different arguments.
What I have tried:
open -n -a "Google Chrome" --args --some-param-A
Fine, a new instance of Chrome is launched. Checking the command line parameters using chrome://version is also OK, --some-param-A is there.
Now I would like to open a second instance but with different command line parameters.
open -n -a "Google Chrome" --args --some-param-B
A second instance is launched, but it is started with --some-param-A again. I need it to start with --some-param-B though.
I also tried the -F (--fresh) option, did not help either. Seems that arguments after --args are read only once.
How can I fix that?
Thanks!
Have you tried passing --user-data-dir to Chrome when you launch it from the command line?
It seems to be a known issue and using --user-data-dir (without a specified directory) is a workaround.
Works Cited:
https://askubuntu.com/questions/35392/how-to-launch-a-new-instance-of-google-chrome-from-the-command-line

Run php file in different browser using terminal other than default browser

Hey guys is there a way to run php file in chrome or in any other browser using terminal.If I run my php file it automatically runs on my default browser but I just want to run on different browser using terminal(Mac OS).
Use the "open" command and specify a different browser with the "-a application" flag.
open -a /path/to/Chrome/binary yourfile.php
Manpage for "open" is here.
Of course, you can also make an alias for that to save typing:
alias chrome="open -a /path/to/Chrome/binary yourfile.php"
then you can just type
chrome
If you have spaces in the path to your Chrome binary, you will need to escape them when defining the alias, something like this:
alias chrome="open -a \"/Applications/Google Chrome.app/contents/MacOS/Google Chrome\" yourfile.php"

Creating an application from a Terminal comand

How would I go about creating a short cut or other type of app that I can just click on with this command:
open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --ignore-certificate-errors
I'm fairly new to this.
I am assuming you are using bash:
open ~/.bash_aliases with your favourite editor and define an alias as follows:
alias chrome_alias='open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --ignore-certificate-errors'
obviously you could modify the name of the alias

Multiple tabs with tmux / tmuxinator and iTerm2

I would like to open all my useful stuff like here in iTerm2:
Not like this:
I'm using tmuxinator I've defined some tabs. I wonder if it's possible to get the former behaviour at all.
I just tried with tmux 1.8. Not totally obvious, but it works.
Here's what you do:
Open iTerm2 (latest, be sure to have at least tmux 1.8 installed).
In iTerm2, run command tmux <your tmuxinator profile>. Then detach ^b d.
In iTerm2, run command tmux -CC attach -t <your session>. You will see your tabs open in different windows.
Open menu Shell->Tmux->Dashboard
Select and hide all the windows.
Select all the hidden windows, and click Open in Tabs.
I'd like to know how to avoid the part about hiding and opening in tabs.
Just wanted to add some comments onto what justingordon mentioned (1).
This all works great. But I found how to streamline step 4-6 so it happens automatically.
Go to iTerm2's Preferences, under General, you will see a section titled tmux. There's an option that says When attaching, open unrecognized windows in. If you change the current selection from Windows to Tabs.
Two extra tips.
If you want you could select the option Automatically hide the tmux client session after connection. This will minimize the iTerm2 window in which you typed
tmux -CC attach
I also enabled the option Focus follows mouse. You can find this option under Preferences then Pointer. It should be the first option on the bottom left.
To use tmuxinator with iterm2 panes, use the following configuration:
attach: false
in combination with
on_project_exit:
- tmux -CC attach -t way
It looks like an issue in the documentations as told here
This is an example that I normally use:
# ~/.tmuxinator/way.yml
name: way
root: ~/learn/ruby/ruby-way/
attach: false
on_project_exit:
- tmux -CC attach -t way
# Runs before everything. Use it to start daemons etc.
on_project_start:
- export EDITOR="emacsclient --server-file=way -c"
- export VISUAL=$EDITOR
- emacs --daemon=way --title=RUBY-WAY
- $EDITOR &
windows:
- console:
- echo "A currar"
- testing:
- echo "A testear"
I hope that this helps.
Add this to your tmuxinator config:
attach: false
post: tmux -CC attach
https://github.com/tmuxinator/tmuxinator/pull/293

Linux equivalent of the DOS "start" command?

I'm writing a ksh script and I have to run a executable at a separate Command Prompt window.
xdg-open is a similar command line app in linux.
see https://superuser.com/questions/38984/linux-equivalent-command-for-open-command-on-mac-windows for details on its use.
I believe you mean something like xterm -e your.sh &
Don't forget the final &
maybe it´s not a seperate window that gets started, but you can run some executables in background using "&"
e.g.
./myexecutable &
means your script will not wait until myexecutable has finished but goes on immediately. maybe this is what you are looking for.
regards
xdg-open is a good equivalent for the MS windows commandline start command:
xdg-open file
opens that file or url with its default application
xdg-open .
opens the currect folder in the default file manager
One of the most useful terminal session programs is screen.
screen -dmS title executable
You can list all your screen sessions by running
screen -ls
And you can connect to your created screen session (also allowing multiple simultaneous/synchronized sessions) by running
screen -x title
This will open up the emulated terminal in the current window where executable is running. You can detach a screen session by pressing C-a C-d, and can reattach as many times as you wish.
If you really want your program started in a new terminal window, you could do something like this:
xterm yourtextmodeprogram
or
gnome-terminal -e yourtextmodeprogram
or
konsole -e mc
Trouble is that you cannot count on a particular terminal emulator being installed, so (again: if you really want to do this) you would need to look for the common ones and then execute the first one encountered.
As Joachim mentioned: The normal way to do this is to background the command (read about shell job control somewhere, if you want to dig deeper).
There are also cases where you want to start a persistent shell, i.e. a shell session which lives on when you close the terminal window. There are two ways to do this:
batch-oriented: nohup command-to-run &
interactive: screen
if you want a new windows, just start a new instance of your terminal application: in kde it's
konsole -e whatever
i'm sure the Gnome terminal has similar options
Some have recommended starting it in the background with &, but beware that that will still send all console output from the application you launch to the terminal you launched it from. Additionally, if you close the initial terminal the program you loaded will end.
If you're using a desktop environment like KDE or GNOME, I'd check the alt+f2 launching apps (gnome-open is the one for GNOME, I don't know the name of the KDE app) and see if you can pass them the command to launch as an argument.
Also, if your intention is to launch a daemon, you should check the nohup documentation.
I used nohup as the following command and it works:
nohup <your command> &
then press enter and enter!
don't forget the last &
for example, I ran a python code listening to port 5000:
nohup python3 -W ignore mycode.py &
then I made sure of running by netstat -tulnp | grep :5000 and it was ok.

Resources