OSX: Environment variables pointing to application bundles? - macos

I want cscope to open files in MacVim instead of vim, so I'm trying to have the path to MacVim as the Value of the EDITOR environment variable which is used by cscope:
$ export EDITOR=/Applications/MacVim.app/Contents/MacOS/MacVim
If I'm now trying to edit a file from within ctags, it won't work and throws this error message:
$ MacVim[8384:10b] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting
Calling MacVim from the commandline with
$ /Applications/MacVim.app/Contents/MacOS/MacVim
works, though.
How can I fix this?

Make sure you put the mvim script in your path, and try this out:
export EDITOR="mvim -f"
This was the ticket for me when using MacVim as editing git commit messages.

Have you tried export EDITOR=/Applications/MacVim.app?
Or wrapping MacVim in a small script that uses open to start the app?

It works fine for me when I set my EXPORT variable to exactly that, and start a git commit. What are you using that's calling it? Have you considered setting EXPORT to point to the mvim script that comes on the MacVim disk image instead?

<plug>
My launch tool is designed for this. It's like Apple's open, but allows you to get the path to an application bundle rather than launching it. For example:
% launch -ni com.apple.safari
/Applications/Safari.app
launch is in Fink and MacPorts too.
</plug>

Related

Can I open the ruby app from Rubymine terminal

I just got Rubymine and getting used to ruby on rails on mac. I'm wondering if there is any command to open a ruby app on Rubymine 7, from terminal.
Would there be a command like this?
$ Rubymine /Path/to/RubyApp
RubyMine has a special menu item for that. In ver. 8, 'Tools' > 'Create command-line launcher ...' Previous versions should keep the item somewhere around.
Once you've created command-line launcher (Tools > Create Command-Line Launcher), you can use the command mine via the command line..
e.g. If you have navigated to a folder via the command line, that you then want to open with Rubymine, you can run mine .
The standard way to do it on bash/OSX from the JetBrains site:
$<RubyMine> <path1> --line<number> <path2>
That's the launcher, the path to the project, the line you want the file to open to and the path to the file in order. An example would be: /Applications/RubyMine.app/Contents/MacOS/rubymine ~/RubyMineProjects/untitled45 --line 1 ~/RubyMineProjects/untitled45/sample.sass These can be pretty long commands, but you can create a symlink to shorten the launcher at least.
Keep in mind that launching from the command line launches with the ruby version you have set there as well as any other command line configs. If you want to keep configurations from the editor you should open the project the conventional way.
it's enough to append the following line into your ~/.bashrc or ~/.zshrc
alias rubymine="open -a rubymine"
reference Use Typora from Shell or Cmd
For RubyMine 2017.1.5, just type Alt + F12 for local terminal
Just go to folder where Rubymine is download.Then go to Rubymine bin folder. And run command from console. In my case
kashif#kashif-HP-ProBook-4520s:~/Downloads/RubyMine-2017.1.6/bin$ ./rubymine.sh
Previous answers didn't help me (using RubyMine 2020.1)
Instructions for Mac (different OSs also described on rubymine docs):
Create a script:
You can create a shell script with this command in a directory from your PATH environment variable. For example, create the file /usr/local/bin/rubymine with the following contents:
#!/bin/sh
open -na "RubyMine.app" --args "$#"
Tada! Assuming that script is executable (in case not - run chmod +x /usr/local/bin/rubymine) Now you are able to navigate to proper directory and run rubymine . to run RubyMine for that directory
If you want to play around with different args passed while starting RubyMine, check rubymine docs.

Installation of MacVim to use gvim

Previously I had gVim running and working; however, my hard drive crashed so everythin'g got erased. Anyways, I am trying to run gVim to open files "-bash: gVim: command not found. I installed X11 and MacVim and did everything that i did before but it just wont open my file. When i open my file with vim it works, but i would prefer gVim.
Any suggestions on how to get givm to work??
I'm not sure you know what you are doing.
MacVim has nothing to do with X11 at all so… are you trying to run GVim — the GTK front end of Vim — under X11 (to mimic a Linux desktop, maybe) or do you simply want to run some GUI Vim (GVim or MacVim, whatever).
If you really want GVim, you can install it (and its dependencies) from source but, judging by your question I don't think you should take that path.
If you only want a GUI Vim, the MacVim download comes with a mvim script that you can put anywhere in your $PATH. $ mvim filename will work just like $ gvim filename on Linux.
You can even rename that script to gvim if you absolutely need a gvim command.
You can install MacVim either from this site:
https://code.google.com/p/macvim/
or for example from the macports project, with port install MacVim (you must install first macports (see www.macports.org)
with macvim you will get the mvim terminal command, what is an small shell script.
TL;DR: gvim is aliased from the MacVim application's bin folder and you can add that bin directory to your $PATH variable to enable access to gvim from the terminal.
I recently downloaded the latest MacVim.dmg file from https://github.com/macvim-dev/macvim/releases, opened it, in the window that pops up, dragged the MacVim icon to the Applications icon, then closed that window and ejected the MacVim.dmg installer from the finder.
From a finder window I navigated to the /Applications folder, I right-clicked on MacVim.app and selected "Show Package Contents". Then I opened Contents/bin and there found a set of symlinks from mvim and gvim to vim.
I opened a terminal, and changed directory to the home directory by typing cd ~ . From the home directory, I typed ls -al to list all files even the hidden ones which start with a dot, and verify there was a .bash_profile file. (If you don't have this file, see if you have any other other profile files, or search the web to determine which to use or add, so that you can set the following additions to your $PATH variable and have them persist after you log out and back in.)
From the home directory, I used my favorite editor to edit the .bash_profile file, and added the following line to add MacVim's bin file to the $PATH variable:
export PATH=$PATH:/Applications/MacVim.app/Contents/bin
I saved and exited the .bash_profile file, then loaded my change with source .bash_profile. Now when I type in the terminal which gvim it lists that location, and I can run gvim from the terminal to open a file.
I’m a hard-core gvim user (i.e., I prefer gvim to vi, vim, mvim, and other text editors that are available on Mac). I’ve searched online for “How to install gvim on Mac?”, and have found many answers. The one answer that works best for me is as follows. Assuming you have brew available, on a terminal, type:
brew install macvim
You may be asked to fix some errors. Just follow the onscreen instructions, which may include running commands: brew unlink vim, brew unlink macvim, etc.
Once your macvim has been installed, type the following command:
brew link macvim
If this is successful, then gvim should have been installed, and you can verify this by typing:
which gvim
You should see:
/usr/local/bin/gvim
as the screen output.

RVM is not being used by Ubuntu Launcher

I'm trying to make my data files "clickable" like a MS Word document. When a user clicks on a file on the desktop with a ".vr" extension, I want it to execute my Ruby script, and pass the file name as a parameter.
I've created a mime type, "text/vr" with the ".vr" extension, and when I click the file, "text.vr" on the desktop, it attempts to run the command:
$vr test.vr
This command fails because it tries to use an old version of Ruby. The problem is that Ubuntu uses a different environment when it launches a program from the desktop instead of the prompt.
I use RVM, and it works perfectly when I write programs in the terminal. However, when I click on the file to launch the vr script, RVM isn't used. I need to find a way to make RVM load when a file is clicked.
What's going on here? What environment file is loaded when you execute a file from the desktop? ~/.bashrc? ~/.profile? How can I make it so my whole computer always finds RVM?
Thanks,
Eric
There are few ways, the environment for desktop is loaded from .profile, add one of this:
source $HOME/.rvm/environments/ruby-1.9.3-p327 #OR:
source $HOME/.rvm/environments/default
to load specific ruby.
sometimes it might not work with sourcing, then adding content of the default file to .profile should work:
cat $HOME/.rvm/environments/default >> ~/.profile
It is required to relogin / restart to apply the changes.

Set environment variables on Mac OS X Lion

When someone says "edit your .plist file" or "your .profile" or ".bash_profile" etc, this just confuses me. I have no idea where these files are, how to create them if I have to do that, etc, and also why there seem to be so many different ones (why? Do they do different things?)
So could someone please explain very patiently to a previous Windows user (wanting desperately to become more familiar with the pleasant if initially somewhat confusing OS X world) how to do this step by step?
I need the variables to be set both for GUI applications and command line applications, and at the moment it's for an ant script that needs the variables, but there will most likely be other needs as well.
Please note that I have Lion too, since many of the answers you get Googling seem to be outdated for Lion...
Also note that I have practically zero experience using the Terminal. I'm willing to learn, but please explain for a novice...
First, one thing to recognize about OS X is that it is built on Unix. This is where the .bash_profile comes in. When you start the Terminal app in OS X you get a bash shell by default. The bash shell comes from Unix and when it loads it runs the .bash_profile script. You can modify this script for your user to change your settings. This file is located at:
~/.bash_profile
Update for Mavericks
OS X Mavericks does not use the environment.plist - at least not for OS X windows applications. You can use the launchd configuration for windowed applications. The .bash_profile is still supported since that is part of the bash shell used in Terminal.
Lion and Mountain Lion Only
OS X windowed applications receive environment variables from the your environment.plist file. This is likely what you mean by the ".plist" file. This file is located at:
~/.MacOSX/environment.plist
If you make a change to your environment.plist file then OS X windows applications, including the Terminal app, will have those environment variables set. Any environment variable you set in your .bash_profile will only affect your bash shells.
Generally I only set variables in my .bash_profile file and don't change the .plist file (or launchd file on Mavericks). Most OS X windowed applications don't need any custom environment. Only when an application actually needs a specific environment variable do I change the environment.plist (or launchd file on Mavericks).
It sounds like what you want is to change the environment.plist file, rather than the .bash_profile.
One last thing, if you look for those files, I think you will not find them. If I recall correctly, they were not on my initial install of Lion.
Edit: Here are some instructions for creating a plist file.
Open Xcode
Select File -> New -> New File...
Under Mac OS X select Resources
Choose a plist file
Follow the rest of the prompts
To edit the file, you can Control-click to get a menu and select Add Row. You then can add a key value pair. For environment variables, the key is the environment variable name and the value is the actual value for that environment variable.
Once the plist file is created you can open it with Xcode to modify it anytime you wish.
Your .profile or .bash_profile are simply files that are present in your "home" folder. If you open a Finder window and click your account name in the Favorites pane, you won't see them. If you open a Terminal window and type ls to list files you still won't see them. However, you can find them by using ls -a in the terminal. Or if you open your favorite text editor (say TextEdit since it comes with OS X) and do File->Open and then press Command+Shift+. and click on your account name (home folder) you will see them as well. If you do not see them, then you can create one in your favorite text editor.
Now, adding environment variables is relatively straightforward and remarkably similar to windows conceptually. In your .profile just add, one per line, the variable name and its value as follows:
export JAVA_HOME=/Library/Java/Home
export JRE_HOME=/Library/Java/Home
etc.
If you are modifying your "PATH" variable, be sure to include the system's default PATH that was already set for you:
export PATH=$PATH:/path/to/my/stuff
Now here is the quirky part, you can either open a new Terminal window to have the new variables take effect, or you will need to type .profile or .bash_profile to reload the file and have the contents be applied to your current Terminal's environment.
You can check that your changes took effect using the "set" command in your Terminal. Just type set (or set | more if you prefer a paginated list) and be sure what you added to the file is there.
As for adding environment variables to GUI apps, that is normally not necessary and I'd like to hear more about what you are specifically trying to do to better give you an answer for it.
Here's a bit more information specifically regarding the PATH variable in Lion OS 10.7.x:
If you need to set the PATH globally, the PATH is built by the system in the following order:
Parsing the contents of the file /private/etc/paths, one path per line
Parsing the contents of the folder /private/etc/paths.d. Each file in that folder can contain multiple paths, one path per line. Load order is determined by the file name first, and then the order of the lines in the file.
A setenv PATH statement in /private/etc/launchd.conf, which will append that path to the path already built in #1 and #2 (you must not use $PATH to reference the PATH variable that has been built so far). But, setting the PATH here is completely unnecessary given the other two options, although this is the place where other global environment variables can be set for all users.
These paths and variables are inherited by all users and applications, so they are truly global -- logging out and in will not reset these paths -- they're built for the system and are created before any user is given the opportunity to login, so changes to these require a system restart to take effect.
BTW, a clean install of OS 10.7.x Lion doesn't have an environment.plist that I can find, so it may work but may also be deprecated.
echo $PATH
it prints current path value
Then do vim ~/.bash_profile and write
export PATH=$PATH:/new/path/to/be/added
here you are appending to the old path, so preserves the old path and adds your new path to it
then do
source ~/.bash_profile
this will execute it and add the path
then again check with
echo $PATH
Unfortunately none of these answers solved the specific problem I had.
Here's a simple solution without having to mess with bash. In my case, it was getting gradle to work (for Android Studio).
Btw, These steps relate to OSX (Mountain Lion 10.8.5)
Open up Terminal.
Run the following command:
sudo nano /etc/paths (or sudo vim /etc/paths for vim)
Go to the bottom of the file, and enter the path you wish to add.
Hit control-x to quit.
Enter 'Y' to save the modified buffer.
Open a new terminal window then type:
echo $PATH
You should see the new path appended to the end of the PATH
I got these details from this post:
http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.UkED3rxPp3Q
I hope that can help someone else
Simplified Explanation
This post/question is kind of old, so I will answer a simplified version for OS X Lion users.
By default, OSX Lion does not have any of the following files:
~/.bashrc
~/.bash_profile
~/.profile
At most, if you've done anything in the terminal you might see ~/.bash_history
What It Means
You must create the file to set your default bash commands (commonly in ~/.bashrc). To do this, use any sort of editor, though it's more simple to do it within the terminal:
%> emacs .profile
[from w/in emacs type:] source ~/.bashrc
[from w/in emacs type:] Ctrl + x Ctrl + s (to save the file)
[from w/in emacs type:] Ctrl + x Ctrl + c (to close emacs)
%> emacs .bashrc
[from w/in emacs type/paste all your bash commands, save, and exit]
The next time you quit and reload the terminal, it should load all your bash preferences. For good measure, it's usually a good idea to separate your commands into useful file names. For instance, from within ~/.bashrc, you should have a source ~/.bash_aliases and put all your alias commands in ~/.bash_aliases.
What worked for me is to create a .launchd.conf with the variables I needed:
setenv FOO barbaz
This file is read by launchd at login. You can add a variable 'on the fly' to the running launchd using:
launchctl setenv FOO barbaz`
In fact, .launchd.cond simply contains launchctl commands.
Variables set this way seem to be present in GUI applications properly.
If you happen to be trying to set your LANG or LC_ variables in this way, and you happen to be using iTerm2, make sure you disable the 'Set locale variables automatically' setting under the Terminal tab of the Profile you're using. That seems to override launchd's environment variables, and in my case was setting a broken LC_CTYPE causing issues on remote servers (which got passed the variable).
(The environment.plist still seems to work on my Lion though. You can use the RCenvironment preference pane to maintain the file instead of manually editing it or required Xcode. Still seems to work on Lion, though it's last update is from the Snow Leopard era. Makes it my personally preferred method.)
Setup your PATH environment variable on Mac OS
Open the Terminal program (this is in your Applications/Utilites folder by default).
Run the following command
touch ~/.bash_profile; open ~/.bash_profile
This will open the file in the your default text editor.
For ANDROID SDK as example :
You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "/Development/android-sdk-macosx" as the directory the SDK is installed in. Add the following line:
export PATH=${PATH}:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools
Save the file and quit the text editor.
Execute your .bash_profile to update your PATH.
source ~/.bash_profile
Now everytime you open the Terminal program you PATH will included the Android SDK.
Adding Path Variables to OS X Lion
This was pretty straight forward and worked for me, in terminal:
$echo "export PATH=$PATH:/path/to/whatever" >> .bash_profile #replace "/path/to/whatever" with the location of what you want to add to your bash profile, i.e: $ echo "export PATH=$PATH:/usr/local/Cellar/nginx/1.0.12/sbin" >> .bash_profile
$. .bash_profile #restart your bash shell
A similar response was here: http://www.mac-forums.com/forums/os-x-operating-system/255324-problems-setting-path-variable-lion.html#post1317516
Open Terminal:
vi ~/.bash_profile
Apply changing to system (no need restart computer):
source ~/.bash_profile
(Also work with macOS Sierra 10.12.1)
I had problem with Eclipse (started as GUI, not from script) on Maverics that it did not take custom PATH. I tried all the methods mentioned above to no avail. Finally I found the simplest working answer based on hints from here:
Go to /Applications/eclipse/Eclipse.app/Contents folder
Edit Info.plist file with text editor (or XCode), add LSEnvironment dictionary for environment variable with full path. Note that it includes also /usr/bin etc:
<dict>
<key>LSEnvironment</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/dev/android-ndk-r9b</string>
</dict>
<key>CFBundleDisplayName</key>
<string>Eclipse</string>
...
Reload parameters for app with
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.fra‌​mework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app
Restart Eclipse
Let me illustrate you from my personal example in a very redundant way.
First after installing JDK, make sure it's installed.
Sometimes macOS or Linux automatically sets up environment variable for you unlike Windows. But that's not the case always. So let's check it.
The line immediately after echo $JAVA_HOME would be empty if the environment variable is not set. It must be empty in your case.
Now we need to check if we have bash_profile file.
You saw that in my case we already have bash_profile. If not we have to create a bash_profile file.
Create a bash_profile file.
Check again to make sure bash_profile file is there.
Now let's open bash_profile file. macOS opens it using it's default TextEdit program.
This is the file where environment variables are kept. If you have opened a new bash_profile file, it must be empty. In my case, it was already set for python programming language and Anaconda distribution. Now, i need to add environment variable for Java which is just adding the first line. YOU MUST TYPE the first line VERBATIM. JUST the first line. Save and close the TextEdit. Then close the terminal.
Open the terminal again. Let's check if the environment variable is set up.
I took the idiot route.
Added these to the end of /etc/profile
for environment in `find /etc/environments.d -type f`
do
. $environment
done
created a folder /etc/environments
create a file in it called "oracle" or "whatever" and added the stuff I needed set globally to it.
/etc$ cat /etc/environments.d/Oracle
export PATH=$PATH:/Library/Oracle/instantclient_11_2
export DYLD_LIBRARY_PATH=/Library/Oracle/instantclient_11_2
export SQLPATH=/Library/Oracle/instantclient_11_2
export PATH=$PATH:/Library/Oracle/instantclient_11_2
export TNS_ADMIN=/Library/Oracle/instantclient_11_2/network/admin
It is recommended to check default terminal shell before setting any environment variables, via following commands:
$ echo $SHELL
/bin/zsh
If your default terminal is /bin/zsh (Z Shell) like in my case (Personally prefer Z Shell), then you should set these environment variable in ~/.zshenv file with following contents (In this example, setting JAVA_HOME environment variable, but same applies to others):
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
More detail, which may perhaps be helpful to someone:
Due to my own explorations, I now know how to set environment variables in 7 of 8 different ways. I was trying to get an envar through to an application I'm developing under Xcode. I set "tracer" envars using these different methods to tell me which ones get it into the scope of my application. From the below, you can see that editing the "scheme" in Xcode to add arguments works, as does "putenv". What didn't set it in that scope: ~/.MACOS/environment.plist, app-specific plist, .profile, and adding a build phase to run a custom script (I found another way in Xcode [at least] to set one but forgot what I called the tracer and can't find it now; maybe it's on another machine....)
GPU_DUMP_DEVICE_KERNEL is 3
GPU_DUMP_TRK_ENVPLIST is (null)
GPU_DUMP_TRK_APPPLIST is (null)
GPU_DUMP_TRK_DOTPROFILE is (null)
GPU_DUMP_TRK_RUNSCRIPT is (null)
GPU_DUMP_TRK_SCHARGS is 1
GPU_DUMP_TRK_PUTENV is 1
... on the other hand, if I go into Terminal and say "set", it seems the only one it gets is the one from .profile (I would have thought it would pick up environment.plist also, and I'm sure once I did see a second tracer envar in Terminal, so something's probably gone wonky since then. Long day....)
Step1: open ~/.bash_profile
Now a text editor opens:
Step2: variable name should be in capitals. in this example variable is NODE_ENV
Step3: export NODE_ENV=development
Save it and close.
Restart your system.
Done.
To check env variable: open terminal and type
echo $NODE_ENV

How to launch an app on OS X with command line - The best way

I want to launch an app on OSX from a script. I need to pass some command line arguments. Unfortunately, open doesn't accept command line args.
The only option I can think of is to use nohup myApp > /dev/null & to launch my app so it can exist independently of the script that launches it.
Any better suggestions?
As was mentioned in the question here, the open command in 10.6 now has an args flag, so you can call:
open -n ./AppName.app --args -AppCommandLineArg
In OS X 10.6, the open command was enhanced to allow passing of arguments to the application:
open ./AppName.app --args -AppCommandLineArg
But for older versions of Mac OS X, and because app bundles aren't designed to be passed command line arguments, the conventional mechanism is to use Apple Events for files like here for Cocoa apps or here for Carbon apps. You could also probably do something kludgey by passing parameters in using environment variables.
An application bundle (.app file) is actually a directory. Instead of using open and the .app filename, you can move into the app's directory and start the actual machine code program located inside. For instance:
$ cd /Applications/LittleSnapper.app/
$ ls
Contents
$ cd Contents/MacOS/
$ ./LittleSnapper
That is the actual binary executable that might accept arguments (or not, in LittleSnapper's case).
In case your app needs to work on files (what you would normally expect to pass as: ./myApp *.jpg), you would do it like this:
open *.jpg -a myApp
You can launch apps using open:
open -a APP_YOU_WANT
This should open the application that you want.
open also has an -a flag, that you can use to open up an app from within the Applications folder by it's name (or by bundle identifier with -b flag). You can combine this with the --args option to achieve the result you want:
open -a APP_NAME --args ARGS
To open up a video in VLC player that should scale with a factor 2x and loop you would for example exectute:
open -a VLC --args -L --fullscreen
Note that I could not get the output of the commands to the terminal. (although I didn't try anything to resolve that)
I would recommend the technique that MathieuK offers. In my case, I needed to try it with Chromium:
> Chromium.app/Contents/MacOS/Chromium --enable-remote-fonts
I realize this doesn't solve the OP's problem, but hopefully it saves someone else's time. :)
Lots of complex answers when you can simply access Applications folder and type:
open -a [APP NAME]
This is it!
I wanted to have two separate instances of Chrome running, each using its own profile. I wanted to be able to start them from Spotlight, as is my habit for starting Mac apps. In other words, I needed two regular Mac applications, regChrome for normal browsing and altChrome to use the special profile, to be easily started by keying ⌘-space to bring up Spotlight, then 'reg' or 'alt', then Enter.
I suppose the brute-force way to accomplish the above goal would be to make two copies of the Google Chrome application bundle under the respective names. But that's ugly and complicates updating.
What I ended up with was two AppleScript applications containing two commands each. Here is the one for altChrome:
do shell script "cd /Applications/Google\\ Chrome.app/Contents/Resources/; rm app.icns; ln /Users/garbuck/local/chromeLaunchers/Chrome-swirl.icns app.icns"
do shell script "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --user-data-dir=/Users/garbuck/altChrome >/dev/null 2>&1 &"
The second line starts Chrome with the alternate profile (the --user-data-dir parameter).
The first line is an unsuccessful attempt to give the two applications distinct icons. Initially, it appears to work fine. However, sooner or later, Chrome rereads its icon file and gets the one corresponding to whichever of the two apps was started last, resulting in two running applications with the same icon. But I haven't bothered to try to fix it — I keep the two browsers on separate desktops, and navigating between them hasn't been a problem.
Beginning with OS X Yosemite, we can now use AppleScript and Automator to automate complex tasks. JavaScript for automation can now be used as the scripting language.
This page gives a good example example script that can be written at the command line using bash and osascript interactive mode. It opens a Safari tab and navigates to example.com.
http://developer.telerik.com/featured/javascript-os-x-automation-example/
osascript -l JavaScript -i
Safari = Application("Safari");
window = Safari.windows[0];
window.name();
tab = Safari.Tab({url:"http://www.example.com"});
window.tabs.push(tab);
window.currentTab = tab;
Simple, here replace the "APP" by name of the app you want to launch.
export APP_HOME=/Applications/APP.app/Contents/MacOS
export PATH=$PATH:$APP_HOME
Thanks me later.
With applescript:
tell application "Firefox" to activate
Why not just set add path to to the bin of the app. For MacVim, I did the following.
export PATH=/Applications/MacVim.app/Contents/bin:$PATH
An alias, is another option I tried.
alias mvim='/Applications/MacVim.app/Contents/bin/mvim'
alias gvim=mvim
With the export PATH I can call all of the commands in the app. Arguments passed well for my test with MacVim. Whereas the alias, I had to alias each command in the bin.
mvim README.txt
gvim Anotherfile.txt
Enjoy the power of alias and PATH. However, you do need to monitor changes when the OS is upgraded.
To Create a New Text File OR open an existing one, in any folder, using a Text/Code Editor like the Free TextMate app on MACOSX, use this command on Terminal:
open -n /Applications/TextMate.app --args "$PWD/some file.txt"
Instead of a Text File, you can use any file type, based on your app's requirements and its support for this syntax.
This command also simulates the New Text Document Here Command on Windows and has been tested on MacBook Pro 2021 and Monterey 12.2.1 successfully.

Resources