I've been running into a rut recently with one project I've been trying to accomplish. Using Automator, but I don't know how to exactly to go about this project. There's this script editing app called Brackets, and I want to make it so whenever the app is opened, the shell command known as tty.js is executed. Any help I can get would be great
2 Answers
What you can try is going to the application's .app folder and renaming the binary, creating a script file (marked executable) named as the executable used to be which will contain a reference the now-renamed executable along with whatever you are scripting. e.g.
cd /Applications/Brackets.app/Contents/MacOS
mv Brackets BracketsReal
echo "tty.js" > Brackets
echo "BracketsReal &" >> Brackets
chmod +x Brackets
That should create a text script that launches your script and the app afterwards...
edit
scripts in Appname.app/Contents/MacOS/ folder are supported.
The first line #!/bin/sh (aka shebang) is required
The technique to move the real executable and make it execute from a script is called wrapping and is also used from applications like Gimp or XQuartz (Xorg/X11) on MacOS.
If I understand correctly what the user was trying to achieve, run Bracket and automatically open the file tty.js, apart the missing shebang, need some other consideration.
To correctly wrap BracketsReal, Brackets should be something like:
#!/bin/sh
exec "$(dirname "$0")/BracketsReal"
That's should run as if we never moved Brackets to BracketsReal.
exec is a built-in command of the shell
$0 is a special argument passed from the system to the executed shell script, when executed with a click should be the full path to the script:
/Applications/Brackets.app/Contents/MacOS/Brackets
dirname is a shell command to get only the directory part without the file name, $( ) is a command substitution, once executed the line will become:
exec /Applications/Brackets.app/Contents/MacOS/BracketsReal
So much so we can move the application from /Applications in other folders and still should run it.
At this point we should check that BracketsReal (probably a script itself) accept files to open as arguments on the command line (and eventually if require some special syntax) if it does accept arguments then the line would become something like:
exec "$(dirname "$0")/BracketsReal" "/path/to/the/file/tty.js"
Last note, to check if something is wrong with the wrapper script just open a terminal and run the wrapper, at the terminal prompt just type/paste:
/Applications/Brackets.app/Contents/MacOS/Brackets
privilegies or syntax errors are printed in the terminal window.
Keyboard Maestro has an option to run a macro when an application is launched:

You might also assign a shortcut to a script like open -a Brackets;tty.js and then always use that script to open Brackets.