open file with particular application where spaces in application name - macos

I want to open ex1.py in the terminal. If I just go:
open ex1.py the file opens in textwrangler.
But I want to use sublime. So I tried this:
open -a SublimeText ex1.py
Unable to find application named 'SublimeText'
open -a Sublime Text 2 ex1.p
The files /Users/macuser/Documents/pyleo/Text and /Users/macuser/Documents/pyleo/2 do not exist.
When I control click sublime > show in finder the name is "Sublime Text 2". Presumably the spaces are causing an issue.
How can I open ex1.py in Sublime text 2 using the terminal?

Wrap the application name in single quotes:
open -a 'Sublime Text 2' ex1.py

Related

All file text in hexa when open folder in Sublime Text Editor

I can work well in Sublime text when I open a single file. However, when I want to open a folder, all the files in that folder will be shown in Hexa and the file name will change to ._filename.
Try opening the file with a different encoding. You can do so using "File > Reopen with Encoding" or put "show_encoding": true in user settings and restart to view the encodings and choose the right one.

Unix Shell .bash_profile script open two files in sublime text in same window

So I have the following code in my .bash_profile file. This code allows me to use the sub command followed by the folder/filename to open that folder/file in sublime text! Thats awesome!
However I'm trying to open the .bash and .bash_profile files in sublime text using the editbashpro command as defined by the alias... however it opens BOTH files in SEPARATE windows.
I do NOT want to fix this issue by changing settings in Sublime Text itself, which it seems all of the tutorials out there are directing me towards this...
Is there any way to open both .bash and .bash_profile in the same window in sublime using only the terminal/bash_profile script? I'm extremely new to the terminal and using shell scripting? idk what its even called? see how new i am?
# Sublime Text Open File/Folder Command
function sub() {
open $1 -a "Sublime Text"
}
echo 'sub <file/folder> ->
open file/folder in sublime
'
# Edit Bash Profiles Command
alias editbashpro='cd ~/;
sub .bash_profile;
sub .bashrc;'
echo 'editbashpro ->
opens .bashrc and .bash_profile in Sublime Text Editor'

Opening Finder from terminal with file selected

I want to open Finder from the terminal with a specific file selected. I know that by using open . I can open the current directory in Finder, but I also want to select some file in the Finder window.
The basic thing I want to do is run a script that randomly selects a file among many in a folder and for that I need to open a new Finder window with the file selected.
The . in your open . command just means path at current location (which would be a folder) so open decides that the correct application to use is Finder. If you were to do open myTextFile.txt which is at your current location in the terminal open will decide to use a text editor instead. You can however specify the application to open the file with by using the -a flag so your command would look like this: open -a Finder myTextFile.txt.
What Faisal suggested will also work, the -R flag is an equivalent to using ⌘↩ (Command Return) in Spotlight.
this and some other nice shell tricks with the open command are described in this post: Shell tricks: the OS X open command
For me, code below works fine.
open -R your-file-path
You can do it like that
osascript -e "tell application \"Finder\"" -e activate -e "reveal POSIX file \"<your file path>\"" -e end tell

How to open .rb file by RubyMine from error message in iTerm2

I'm using iTerm2 and RubyMine in Mavericks.
In iTerm I can open a file from error message by clicking file name with Command key.
But somehow the .rb file is opend SublimeText.
I changed association of the file to RubyMine in Finder.
(Select a .rb file` -> Open Menu -> Open File with: RubyMine -> All type of files are opend same Application)
But it seems to be valid only in Finder.
How can I configure so that I can open .rb file by RubyMine from iTerm?
If you want to open the file on the given line, you can use the second parameter in Semantic History settings of iTerm2. The line number should be passed as the --line parameter to rubymine:
path_to_rubymine --line \2 \1
See Rubymine and iTerm2 help for more info.
Go to iTerm2 > Preferences > Profiles > Advanced.
Under Semantic History
Change to Run command... with the value open \1

bash open .html file not in browser but with $editor

I want to open all of my html/css/js etc. not in the Browser by typing open example.html, but with my default Editor. I did create the alias EDITOR already, but it does not work with every kind of file.
How to fix that?
Depending on the actual behavior you're looking for, you will probably want one of the following, from the open man page:
-e Causes the file to be opened with /Applications/TextEdit
-t Causes the file to be opened with the default text editor, as deter-
mined via LaunchServices
-f Reads input from standard input and opens the results in the default
text editor. End input by sending EOF character (type Control-D).
Also useful for piping output to open and having it open in the
default text editor.
-W Causes open to wait until the applications it opens (or that were
already open) have exited. Use with the -n flag to allow open to
function as an appropriate app for the $EDITOR environment variable.
Try reading the man page: man open
I see three options:
-a
-a application
Specifies the application to use for opening the file
open -a SomeEditor file.html
-e
Causes the file to be opened with /Applications/TextEdit
open -e file.html
-t
Causes the file to be opened with the default text editor, as determined via LaunchServices
open -t file.html
If you use TextMate or Sublime Text, you can use mate or subl. You can create aliases like this for other editors:
alias wrang="open -a TextWrangler"
open -t opens files in the default application for public.plain-text files. You can change it by adding a line like this to a duti configuration file:
com.macromates.TextMate.preview public.plain-text all

Resources