1

For example in the tutorial here tell application "Finder" Finder is an app in my system. Terminal as well. However, if I replace Terminal with iTerm which is also an App named like that in my applications list, it wouldn't work. Even it is shown in some of the answer from SO like following

#!/bin/bash
osascript -e '
  tell app "iTerm"
    activate
    tell the first terminal
      launch session "Default Session"
      tell the last session
        set name to "New Session"
        write text "cd /usr/bin; ls"
      end tell
    end tell
  end tell'

it will return error of 52:60: syntax error: Expected class name but found identifier. (-2741)

Or something like

#!/bin/bash
osascript -e '
   tell application "Terminal"
   do script "date"
   activate
   end tell'

It works, but when I replace Terminal to iTerm it returns error of 35:41: syntax error: Expected end of line but found “script”. (-2741)

So suspect I am using the wrong app name even it appears to be iTerm is the actual app name, but it seems not, as it caused error above. If I can have a list of the actual app names I can use, it may help me to tackle it *NOTE: I do have iTerm installed, and that's why I want to refer to it...

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121
  • Just to clear up your error, I'd start by looking at the **iTerm AppleScript Dictionary** in **Script Editor** in the **Library** available from the **Window** _menu_, or press **⇧⌘L** in **Script Editor**. If **iTerm** is not listed, then add it. Also, you can use the `#!/usr/bin/osascript` _shebang_ in place of the `bash` _shebang_ and then just have your **AppleScript** _code_. Make the file executable and run it like any other command line utility. – user3439894 Dec 19 '17 at 16:24
  • @user3439894 I did that with 2nd example, and now I get error `./start:local.sh:31:37: script error: Expected end of line but found “script”. (-2741)` – ey dee ey em Dec 19 '17 at 16:32
  • For the first script, looking in the iTerm AppleScript Dictionary, it doesn't have `terminal` so `tell the first terminal` is not proper form, and the `name` _property_ of a `window` is read only, so ` set name to "New Session"` is going to error out too. – user3439894 Dec 19 '17 at 16:55
  • For the second script, read the Description in: https://paste.ee/p/4SQ5P – user3439894 Dec 19 '17 at 17:01
  • @user3439894 yes but what I am trying to do is open iTerm instead of Terminal... I guess I am not understanding your answer? – ey dee ey em Dec 19 '17 at 17:04
  • Sorry, if you read the iTerm AppleScript Dictionary in Script Editor, iTerm does not support the `do script` command. – user3439894 Dec 19 '17 at 17:13
  • @user3439894 I guess I will try shell script instead... apple script is very interesting but seems can limit me only to mac os system.... – ey dee ey em Dec 19 '17 at 17:15
  • You can't do that. **AppleScript dictionaries are not interchangeable.** Every application which supports AppleScript provides its own individual dictionary. To check if an application supports AppleScript at all drag its icon onto the Script Editor in the dock or in `/Applications`. – vadian Dec 20 '17 at 20:11

0 Answers0