MAC os terminal shell not working properly with open command - macos

Does anyone know what's going on when I open up the new shell in MAC?
I checked my ~/.bash_profile, and I don't think there's problem.
Also, I set a alias of chrome="open -a 'Google Chrome'" for my project, but when I try to do the command, chrome index.html, under my project directory in terminal, it's just google's new page that pops up instead of my project page. I tested with other command such as open index.html, it works opening up Safari. But I need google Chrome page for my project.

You're missing the closing quote (') on line 7:
alias ls='ls -G'
# was missing -^

Related

Its possible to change the "webstorm" shell command to open a file in WebStorm?

I open files in WebStorm from the terminal with the command webstorm . when I'm working in a directory.
Is there a way to change the command webstorm to anything more, like wstorm or something shorter to open files fluently?
I'm using macOS.
I Know one way but it's temporary, works untill you close the terminal.
-in your terminal
W=webstorm
then you can use $W in your command instead of webstorm.
Looks like the hint above is very good.
So assuming the shell script "webstorm" is working and your question is how to modify the command AND you want to do it fluently.
Make an alias (your shell may vary, mine is bash)
in the appropriate 'dot' file for your shell
add an alias for webstorm -e like this
alias we='webstorm -e'
now when I want to open a file quickly I type
we filename
And this opens Webstorm in LightEdit mode which opens faster and has a link to access full IDE.
Works like a charm. Also, you could make more than one alias so say ws for the full ide. Enjoy

Open windows file share in Finder on Mac via shell script

My Windows-using colleague gave me a url that looks like this:
\\server\share\folder
I'm able to access it on my Mac, via Finder by translating it to:
smb://server/share/folder
Would like to write a little bash script to prepend the smb: and flip the wacky backslashes to forward slashes.
My question is: how to open Finder via shell script? and can I feed Finder a url?
To open the Finder via a shell script on a Mac simply do:
open DIR
... where DIR is the directory you want to open. The Mac OS will open Finder, since that is the correct application for directories. e.g.
open .
... will open the current directory in a Finder window. You should be able to open an smb:// path with that too. The Mac OS should recognize the smb:// prefix and open the appropriate program. If you pass it an http:// path, it'll open using the default web browser.
I was able to accomplish this by making the following shell script which is called via Automator via a keyboard shortcut when the desired Windows path is selected:
OUTPUT=$(echo "$1" | sed 's/\\/\//g')
A="${OUTPUT#*Production}"
foo="smb://path/to/network/directory${A}"
open "$foo"
Here's what it looks like in Automator:

How do I launch brackets.io from MacOS 10.12 (Sierra) terminal?

I'm having problem launching brackets.io from terminal on MacOS Sierra.
brackets filename.ext
Gives:
-bash: brackets: command not found
Anyone know what I need to configure to make this happen?
Open Bracket editor
Go to file menu and the go to Install Command Line Shortcut
There you have it, to test it go to the terminal and test it
Go to terminal.
type open -a brackets filename.ext
Open Brackets Application:
Mac: Select File > Install Command Line Shortcut in Brackets
Windows: When installing Brackets, ensure Add "brackets" launcher to PATH for
command line use is checked off
Examples
Open a file in the current folder, without switching projects:
brackets index.html
Open two files from a specific path, without switching projects:
brackets ~/Sites/index.html ~/Sites/index.css
Open the current folder as a project in Brackets:
brackets .
Open a specific folder as a project in Brackets: brackets
~/Sites/mysite
Source: https://github.com/adobe/brackets/wiki/Command-Line-Arguments
You can do what is called "creating an alias".
Open your .profile with the editor of your choice. f.e.
pico ~/.profile
or with Brackets like this:
open -a /Applications/Brackets.app/ ~/.profile
and add
alias brackets='open -a /Applications/Brackets.app/
to that file.
save.
close.
done.
First, make a custom command for this by opening your bash_profile and putting in the following code:
function brackets() {
open -a brackets $1
}
Now you can open files and folders in brackets by opening a new terminal window and typing:
brackets <file or folder name>
MacOS 10.15 or greater with zsh
Mac now uses zsh instead of bash, and the GUI option mentioned at https://stackoverflow.com/a/51118156/895245 only adds it to the bash path as of Brackets 1.14. But you can just add it to your PATH manually by adding to:
~/.zprofile
the line:
PATH="$PATH:/usr/local/bin/

how to open a new tab in bash console from bashrc in windows

I have windows 8 on my laptop and I'm trying to create a bash function in bashrc that would allow me to open few files in sublime text and launch opera and chrome at the same time, I'd love to set my working environment up with a simple command from console.
However, when I tried to do it from a single tab, I found out that after launching the editor the tab is processing it and that's it, it doesnt open the browsers. So, I figured, I should probably create a new tab in console that would take care of opening the opera and chrome, but I dont know how to do that from bash.
I tried googling the problem for couple of hours, I saw a lot of info for users of linux but none for windows users.
Here is my bash function, maybe seeing it might help you guys:
alias sl="/c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe" $* #(its my alias for sublime text)
alias browsers="opera & chrome" $* #(another one for opening the browsers)
run () {
cd Users/Man/
sl .bashrc tasks.txt
cd Desktop/work/her*/
sl Gulp*
cd /less\ components/src/
sl *
cd ../../html\ components/
sl *
browsers
}
Or, guys, maybe there is some other way to set up the environment with only one command in console.
I'm using cmder for windows

Open an ipython notebook via double-click on osx

I've downloaded a couple of ipython notebooks, and I'd like to open them in browser tabs without navigating to the directory I've downloaded them to and running ipython notebook notebook_name.ipynb.
I realize this probably means I'm lazy, but it seems like a common use case to me. Am I missing something obvious?
Use Pineapple application for opening and working on your IPython/Jupyter notebooks. It is pretty cool.
Update:
Now there is nteract, which is a new jupyter-like Desktop app. After installing it, make it the default app for opening .ipynb files. Then just double-click any notebook to start it right away.
I have found a nice way using Automator (Oct. 2017; with information from here):
open Automator and create a new Application
to add Run Shell Script drag and drop it from the list; might need these settings Shell: /bin/bash and Pass input: as arguments
insert the code below; if necessary adjust the path to jupyter
Code
#!/bin/sh
variable="'$1'"
the_script='tell application "terminal" to do script "/usr/local/bin/jupyter notebook '
osascript -e "${the_script}${variable}\""
save the script as an application (!)
try to open a .ipynb file and change the default app to this newly created one.
notes
This will open a terminal and run the jupyter notebook command, such that you can interrupt and stop the notebook-server from there.
Also note that you cannot test the app like that in Automator, but need to add the Get Specified Finder Items and insert some test notebook there (just for testing purposes).
As pointed out in the comments, there are two more notes:
To avoid spamming your browser history with notebooks, you can start your notebooks in incognito/private mode: Run jupyter notebook in incognito window
If you want to run notebooks in one server and don't mind an extra tool, Sachit Nagpal has pointed out (thank you), that one could also use nbopen. To use this workflow just replace "/usr/local/bin/jupyter notebook ' with "nbopen '. Any other tool should work alike.
pip install nbopen.
open Automator, create new Application
Drag'n drop Run Shell Script
Change Pass input to as arguments
Copy/paste this script:
variable="'$1'"
the_script='tell application "terminal" to do script "nbopen '
osascript -e "${the_script}${variable}\""
Save the new application to Applications directory as nb_open
Right click any ipynb file and select "Open with > Other" and select the nb_open in the Applications folder. Don't forget to check "Always Open With".
Select an ipynb file, get info (command + i) > Open With (select nb_open if not selected already) > Click Change All.... Done.
The application posted here worked pretty well for me: http://bioequity.org/2013/11/16/ipynbviewer/
You also need to download iTerm2, as described on that page.
Note that this doesn't work if there are spaces in the filename, but you can modify it so that it works with spaces in the filename. Control-click on the iPyNbViewer.app and select "Show package contents". Edit the file Contents/Resources/Scripts/main.scpt. Change three instances of "POSIX path" to "quoted form of POSIX path". Now it will work with spaces in the filename.
To set all of your .ipynb files to open with the app, you'll need to Get Info (command-I) on one of the files and select the iPyNbViewer app to open all .ipynb files.
It would be great if this was the default behavior of double-clicking on an iPython notebook file...
I came up with a way of doing it on Ubuntu. (It works for me but I can take no responsibility). It's explained here. In a nutshell, you need to create a new MIME type, then write a script that works as the app that launches them:
#!/bin/bash
netstat -tln |grep "8902"
# if not found - equals to 1, start it
if [ $? -eq 1 ]
then
ipython notebook / --no-browser --port=8902 &
sleep .5
fi
xdg-open http://localhost:8902/notebooks$1
This always opens the notebook server on port 8902, but first checks whether there is already a server running, and, if so, uses it.
Then you can use ubuntu tweak to select your script as a default application for the MIME type "IPython Notebook" you just created.
Not very elegant, but worth it, in my opinion.
PyCharm now supports Jupyter ipynb files:
which is from the documentation https://www.jetbrains.com/help/pycharm/editing-jupyter-notebook-files.html.
But I think this feature is only available in the Professional version now; hopefully it will be added to the Community version in the future.
Look at this link.
Put a bash script in the folder where you keep your ipython notebooks and simply double click it to open up a notebook instance. From the link above, the bash script has just:
path=$0 # path is path to this file
cd ${path%/*.*} # clip off the file name to get directory path and cd
ipython notebook --pylab inline
Finally, you need to chmod u+x the script to make it executable and you're done.
I have used the command line application 'nbopen' and put it in a Platypus wrapper to get drag'n drop and double click opening on Macos. 'nbopen' is downloadable using 'pip'
It works well when used as described above by DanHickstein.
Only problem with my code is that it requires the full path to the nbopen command. I know I should be able to use 'which nbopen' somehow but can't get it to work.
Heres my Platypus code:
#!/bin/bash
# Opens ipynb files in a Jupyter Notebook
# echo $1
# $1 is the path of the dropped file
/Users/robw/anaconda/bin/nbopen $1
# Based on an idea from
# https://www.quora.com/Is-there-a-straightforward-way-to-open-an-IPython-Notebook-in-Windows-by-double-clicking

Resources