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

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"

Related

open -a Terminal filename argument doesn't work at all, on mac osx

I'm trying to open a C file already compiled using
open -a Terminal filename argument
It's actually a simple server.c file.
I need also to pass the port as argument, but i can't find out how to do it.
"open -a Terminal proxy 8000"
it returns: "The file /Users/...../8000 does not exist."
So i've tried:
"open -a Terminal proxy\ 8000"
it returns: "The file /Users/...../proxy 8000 does not exist."
Of course if i do "./proxy 8000"
It works.
So i definitely need to pass di parameter as argument in command line, but i can't find out any help even in stackoverflow.
Any help?
Thanks!
The open command is meant to open simple files, it doesn't really support your use case. There's an --args option that passes arguments to the application it uses to open the file (i.e. Terminal), but it doesn't look like Terminal passes those on.
AppleScript might work for you though, e.g. from the shell:
osascript -e 'tell application "Terminal" to do script "/path/to/proxy 8000"'

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

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

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.

How do I open a file in Vim from inside a Conque shell

Often I find my self navigating the filesystem from a Conque shell in Vim and want to open a specific file inside my existing MacVim session. Is this possible ? - I was hoping for something like:
shell> open some/file.txt
and then have file.txt pop up inside my existing Vim window (preferably in a new tab).
Note: I am using #wycats vim dot files (not sure this matters).
Type from ConqueShell
mvim --remote-tab-silent filename
This will open the file in a new tab in MacVim
You could also write a Bash alias to shorten the command (assuming you are using bash).
Put in your ~/.profile
alias vim='mvim --remote-tab-silent'
this would enable you to type
vim filename
from ConqueShell or bash, and have it open in a new MacVim tab, rather than terminal vim. It of course does disable your ability to run standard vim (although you could still use the vi command), so maybe you would want to name the alias differently.
Just to add, this will work only if you placed the mvim executable on your path E.G. /usr/bin/mvim. It comes with the MacVim.app
Often I find my self navigating the filesystem from a Conque shell
The beauty of running a shell from inside vim is you have all of vim and the shell at your disposal.
gf is your friend. Once you get the file you want displayed on the screen in some way, you can enter normal mode, move the cursor to the file you want to edit, then use the gf command to navigate to the file. There are many ways to use this. Any program or command that outputs file names is great for this (ll, git status, etc). You could also type the filename into the shell, just to make it visible on the screen without actually running any terminal commands (tab completion is handy here).
It is possible, you can start vim as server and then add as many files as you want, but I'm not very familiar with this, so I can't give you just a direction.

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