0

Struggling with this bit too long, trying my luck here.

I'm running a simple task with applescript which is wrapped inside condition:

If application iTerm2 is running.

If the iterm2 is running, then everything is fine and the execution is successful but if iTerm2 is closed then I'm getting the following syntax error:

132:138: syntax error: Expected end of line but found class name. (-2741)

If it matters I'm, running it via Alfred

Here's the script

on run
  if application "iTerm2" is running then
    tell application "iTerm2"
      tell current window
        create tab with default profile
      end tell
    end tell
  end if
end run

Any help is much appreciated, thanks

Daniel Krom
  • 9,751
  • 3
  • 43
  • 44
  • I do not have or use Alfred; however, testing your code in Script Editor it does not throw an error. So it may well be an Alfred related issue. That said, your code as currently written while testing to see it iTerm2 is running, it's not testing to see it there is a window open. In other words if iTerm2 is running without a window open, nothing happens. Which of course is fine if that is what you want. – user3439894 Mar 30 '19 at 13:14

1 Answers1

0

why do you need the if clause? Try this and it should start iTerm2 if it's not running:

on run
tell application "iTerm2"
  activate
  tell current window
    create tab with default profile
  end tell
end tell
end run
Pat_Morita
  • 3,355
  • 3
  • 25
  • 36