Launch an app on OS X with command line

前端 未结 12 1005
北恋
北恋 2020-12-04 06:03

I want to launch an app on OSX from a script. I need pass it command line arguments. Unfortunately, open doesn\'t accept command line args.

The only opt

相关标签:
12条回答
  • 2020-12-04 06:32

    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
    
    0 讨论(0)
  • 2020-12-04 06:32

    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.

    0 讨论(0)
  • 2020-12-04 06:34

    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;
    
    0 讨论(0)
  • 2020-12-04 06:39

    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.

    0 讨论(0)
  • 2020-12-04 06:40

    You can launch apps using open:

    open -a APP_YOU_WANT
    

    This should open the application that you want.

    0 讨论(0)
  • 2020-12-04 06:41

    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)

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