open programs with applescript

后端 未结 6 587
刺人心
刺人心 2021-02-02 10:39

2 part question:

I\'m simply trying to run programs using applescript from the terminal, so I tried:

$ osascript tell application \"iTunes\" to activate
         


        
相关标签:
6条回答
  • 2021-02-02 11:19

    In a bash shell (like in Terminal), you can send multiple lines to osascript by using a "here document".

    osascript -e "tell application \"iTunes\"" -e "activate" -e "end tell"
    

    becomes

    osascript <<EOF
    tell application "iTunes"
       activate
    end tell
    EOF
    

    As an old-skool Unix hacker, I save these little snippets in my $HOME/bin directory and call them from the command line. Still learning the particulars, though.

    Alan

    0 讨论(0)
  • 2021-02-02 11:20

    Try:

    do shell script "open /Applications/iTunes.app"
    
    0 讨论(0)
  • 2021-02-02 11:36

    Try this. Notice you use "-e" when you are writing the command. Without "-e" you would give a path to an applescript to run. Also notice the string command must be in quotes.

    osascript -e "tell application \"iTunes\" to activate"
    

    And if you have a multi-line applescript you use "-e" before each line like this...

    osascript -e "tell application \"iTunes\"" -e "activate" -e "end tell"
    

    If you want to open an application just use the unix "open" command...

    open "/path/to/application"
    

    If you wanted to open an application using applescript and the "activate" command doesn't work (it should work for almost everything though) then tell the Finder to open it. Remember that applescript uses colon delimited paths...

    osascript -e "tell application \"Finder\" to open file \"path:to:application\""
    
    0 讨论(0)
  • 2021-02-02 11:36

    an alternative to osascript:

    open -a Calendar
    

    close by:

    pkill Calendar
    
    0 讨论(0)
  • 2021-02-02 11:43

    you need to put single quotes around the tell:

    osascript -e 'tell app "iTunes" to activate'

    otherwise you're defining a variable when you run -e

    0 讨论(0)
  • 2021-02-02 11:44

    I'am new to script too.

    I am confused to so I scan an essay named AppleScript Language Guide and when I go through script commands items, I learn that if you want to activate an application in mac os with applescript editor you should type beneath code in your editor and then compile and run them! may this answer will help you, here's code:

    // applescript editor code    
    
    ----------    
    
    activate application "iTunes" line 1    
    
    ----------    
    
    tell application "iTunes" to activate line 2
    
    0 讨论(0)
提交回复
热议问题