pohmelie / run-in-terminal

Atom package for run some commands in terminal, or just run terminal
MIT License
17 stars 7 forks source link

Updated a example in README for Mac users #15

Closed Kee-Wang closed 7 years ago

pohmelie commented 7 years ago

Ok, I think I got it. You try to pass test.py as main target to terminal, so terminal will read shebang and run python. But run-in-terminal purpose is to build launchers for you. So if you have python in your environment and set proper interpolation arguments, then everything will work fine. Please paste here open --help and open -a /Applications/Utilities/Terminal.app --help, cause I can't find mans :cry:

Kee-Wang commented 7 years ago

@pohmelie man open:

Short version:

Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s ][-b ] [-a ] [filenames] [--args arguments] Help: Open opens files from a shell. By default, opens each file using the default application for that file.
If the file is in the form of a URL, the file will be opened as a URL. Options: -a Opens with the specified application. -b Opens with the specified application bundle identifier. -e Opens with TextEdit. -t Opens with default text editor. -f Reads input from standard input and opens with TextEdit. -F --fresh Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents. -R, --reveal Selects in the Finder instead of opening. -W, --wait-apps Blocks until the used applications are closed (even if they were already running). --args All remaining arguments are passed in argv to the application's main() function instead of opened. -n, --new Open a new instance of the application even if one is already running. -j, --hide Launches the app hidden. -g, --background Does not bring the application to the foreground. -h, --header Searches header file locations for headers matching the given filenames, and opens them. -s For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched. Otherwise the highest versioned SDK in each platform is used.

Full Version

OPEN(1) BSD General Commands Manual OPEN(1)

NAME open -- open files and directories

SYNOPSIS open [-e] [-t] [-f] [-F] [-W] [-R] [-n] [-g] [-h] [-s sdk] [-b bundle_identifier] [-a application] file ... [--args arg1 ...]

DESCRIPTION The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified files.

 If the file is in the form of a URL, the file will be opened as a URL.

 You can specify one or more file names (or pathnames), which are interpreted relative to the shell or Terminal window's current
 working directory. For example, the following command would open all Word files in the current working directory:

 open *.doc

 Opened applications inherit environment variables just as if you had launched the application directly through its full path.
 This behavior was also present in Tiger.

 The options are as follows:

 -a application
     Specifies the application to use for opening the file

 -b bundle_indentifier
     Specifies the bundle identifier for the application to use when opening the file

 -e  Causes the file to be opened with /Applications/TextEdit

 -t  Causes the file to be opened with the default text editor, as determined 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.

 -F  Opens the application "fresh," that is, without restoring windows. Saved persistent state is lost, except for Untitled docu-
     ments.

 -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.

 -R  Reveals the file(s) in the Finder instead of opening them.

 -n  Open a new instance of the application(s) even if one is already running.

 -g  Do not bring the application to the foreground.

 -h  Searches header locations for a header whose name matches the given string and then opens it.  Pass a full header name (such
     as NSView.h) for increased performance.

 -s  For -h, partial or full SDK name to use; if supplied, only SDKs whose names contain the argument value are searched. Otherwise
     the highest versioned SDK in each platform is used.

 --args
     All remaining arguments are passed to the opened application in the argv parameter to main().  These arguments are not opened
     or interpreted by the open tool.

EXAMPLES "open '/Volumes/Macintosh HD/foo.txt'" opens the document in the default application for its type (as determined by LaunchSer- vices).

 "open '/Volumes/Macintosh HD/Applications/'" opens that directory in the Finder.

 "open -a /Applications/TextEdit.app '/Volumes/Macintosh HD/foo.txt'" opens the document in the application specified (in this
 case, TextEdit).

 "open -b com.apple.TextEdit '/Volumes/Macintosh HD/foo.txt'" opens the document in the application specified (in this case, TextE-
 dit).

 "open -e '/Volumes/Macintosh HD/foo.txt'" opens the document in TextEdit.

 "ls | open -f" writes the output of the 'ls' command to a file in /tmp and opens the file in the default text editor (as deter-
 mined by LaunchServices).

 "open http://www.apple.com/" opens the URL in the default browser.

 "open 'file://localhost/Volumes/Macintosh HD/foo.txt'" opens the document in the default application for its type (as determined
 by LaunchServices).

 "open 'file://localhost/Volumes/Macintosh HD/Applications/'" opens that directory in the Finder.

 "open -h NSView" lists headers whose names contain NSView and allows you to choose which ones to open.

 "open -h NSView -s OSX10.12" lists headers whose names contain NSView in the MacOSX 10.12 SDK and allows you to choose which ones
 to open.

 "open -a Xcode -h NSString.h" quickly opens /System/Library/Frameworks/Foundation.framework/Headers/NSString.h in Xcode.

HISTORY First appeared in NextStep.

Mac OS X February 10, 2004 Mac OS X

Kee-Wang commented 7 years ago

@pohmelie both 'open --help' and 'open -a /Applications/Utilities/Terminal.app --help' won't work in my terminal. So just I got the man page for open. And I can't get a man page for 'open -a /Applications/Utilities/Terminal.app'.

pohmelie commented 7 years ago

Try: open -a /Applications/Utilities/Terminal.app --args for Terminal with arguments and -e for Terminal execution argument

pohmelie commented 7 years ago

And of course we need terminal.app documentation.

Kee-Wang commented 7 years ago

I couldn't find a documentation for terminal.app.

Moreover, terminal argument is useless in my case. The reason I added -e is because the default argument will surely fail the execution. Actually I can simply put a whitespace in the terminal execution argument and it still works.

pohmelie commented 7 years ago

Did you try above parameters?

Kee-Wang commented 7 years ago

Do you mean open -a /Applications/Utilities/Terminal.app --args one? Yes I did.--args is not a valid flag here, so it didn't work even with -e.

pohmelie commented 7 years ago

I don't get why --args is not valid. Try to make such command right in terminal, which will be proper for starting terminal and python interpreter with filename as argument. Does python filename.py works from terminal?

Kee-Wang commented 7 years ago

I tired open -a /Applications/Utilities/Terminal.app --args in terminal directly, nothing happened. Neither did open -a /Applications/Utilities/Terminal.app.

python filename.py is a valid command and will execute filename.py using python

pohmelie commented 7 years ago

Try something like open -a /Applications/Utilities/Terminal.app --args sleep 1 Probably terminal starts and closes too fast. And without terminal manual we can't move forward.

Kee-Wang commented 7 years ago

I tried with open -a /Applications/Utilities/Terminal.app --args sleep 1. Nothing happened.

pohmelie commented 7 years ago

It looks like there is no possibility to pass commands to terminal, we can only open it with open -n /Applications/Utilities/Terminal.app {working_directory} Or, as you said, there should be shebang and file should be marked as executable which chmod +x.

pohmelie commented 7 years ago

I've made some changes, check it out.

Kee-Wang commented 7 years ago

Yep and it looks great...

except that I made few typos such as

*Notice that Settings only need to configure once. But every test.py files (--> file) has to be changed into excutable and added shebang.

You can keep those typos if you don't mind :)