Executing Shell Scripts from the OS X Dock?

前端 未结 9 1695
自闭症患者
自闭症患者 2020-12-22 17:15

How do I set up a shell script to execute from the Mac OSX dock? It seems that simply creating a shortcut will open the file in my editor. Is there a flag I need to set som

相关标签:
9条回答
  • 2020-12-22 17:35

    Someone wrote...

    I just set all files that end in ".sh" to open with Terminal. It works fine and you don't have to change the name of each shell script you want to run.

    0 讨论(0)
  • 2020-12-22 17:40

    In the Script Editor:

    do shell script "/full/path/to/your/script -with 'all desired args'"

    Save as an application bundle.

    As long as all you want to do is get the effect of the script, this will work fine. You won't see STDOUT or STDERR.

    0 讨论(0)
  • 2020-12-22 17:51

    As long as your script is executable and doesn't have any extension you can drag it as-is to the right side (Document side) of the Dock and it will run in a terminal window when clicked instead of opening an editor.

    If you want to have an extension (like foo.sh), you can go to the file info window in Finder and change the default application for that particular script from whatever it is (TextEdit, TextMate, whatever default is set on your computer for .sh files) to Terminal. It will then just execute instead of opening in a text editor. Again, you will have to drag it to the right side of the Dock.

    0 讨论(0)
  • 2020-12-22 17:53

    You could create a Automator workflow with a single step - "Run Shell Script"

    Then File > Save As, and change the File Format to "Application". When you open the application, it will run the Shell Script step, executing the command, exiting after it completes.

    The benefit to this is it's really simple to do, and you can very easily get user input (say, selecting a bunch of files), then pass it to the input of the shell script (either to stdin, or as arguments).

    (Automator is in your /Applications folder!)

    Example workflow

    0 讨论(0)
  • 2020-12-22 17:53

    I know this is old but in case it is helpful to others:

    If you need to run a script and want the terminal to pop up so you can see the results you can do like Abyss Knight said and change the extension to .command. If you double click on it it will open a terminal window and run.

    I however needed this to run from automator or appleScript. So to get this to open a new terminal the command I ran from "run shell script" was "open myShellScript.command" and it opened in a new terminal.

    0 讨论(0)
  • 2020-12-22 17:56

    If you don't need a Terminal window, you can make any executable file an Application just by creating a shell script Example and moving it to the filename Example.app/Contents/MacOS/Example. You can place this new application in your dock like any other, and execute it with a click.

    NOTE: the name of the app must exactly match the script name. So the top level directory has to be Example.app and the script in the Contents/MacOS subdirectory must be named Example, and the script must be executable.

    If you do need to have the terminal window displayed, I don't have a simple solution. You could probably do something with Applescript, but that's not very clean.

    0 讨论(0)
提交回复
热议问题