Friday, May 29, 2020

#1 2020-04-03 12:51:01 pm

Danjuan
Member
Registered: 2020-04-02
Posts: 14

error "iTerm got an error: TERM environment variable not set."

Trying to open the current finder window in iTerm but i get the following error

error "iTerm got an error: TERM environment variable not set." number 1

Applescript:


tell application "Finder"
   if exists Finder window 1 then
       set currentFolder to target of Finder window 1 as alias
   else
       return
   end if
end tell
tell application "iTerm"
   activate
   do shell script "cd " & quoted form of POSIX path of currentFolder & "; clear"
   activate
end tell

If I change the line: tell application "iTerm" to tell application "Terminal" it works.

I'd really like it to work with iTerm as my colour scheme is setup the way I want.


Filed under: terminal, applescript, iterm

Offline

 

#2 2020-04-04 03:08:14 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: error "iTerm got an error: TERM environment variable not set."

peavine wrote:

I don't have iTerm to test with but you might want to try the following:

Applescript:

tell application "Finder"
   if exists Finder window 1 then
       set currentFolder to target of Finder window 1 as alias
   else
       return
   end if
end tell
tell application "iTerm"
   activate
   do script "cd " & quoted form of POSIX path of currentFolder & "; clear"
   activate
end tell


The problem is: the iTerms.app doesn't have do script command like Terminal.app.
So, your script even doesn't  compile.

Last edited by KniazidisR (2020-04-04 04:07:20 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-04-04 04:10:48 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 481

Re: error "iTerm got an error: TERM environment variable not set."

KniazidisR wrote:

The problem is: the iTerms.app doesn't have do script command like Terminal.app.
So, your script even doesn't  compile.


KniazidisR. Thanks for trying that. It's of no use, so I'll delete my post.

Last edited by peavine (2020-04-04 04:14:38 pm)


2018 Mac mini - macOS Catalina

Offline

 

#4 2020-04-04 04:54:56 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: error "iTerm got an error: TERM environment variable not set."

Now, assuming we use already the zsh shell as default, instead of the bash shell:

1) The iTerms.app doesn't have do script command like Terminal.app to do script telling directly to iTerms.app
2)  I can't find equivalent of bash's clear command in the zsh shell.

Using GUI scripting I can solve the OP's problem this way:

Applescript:


----------------------------------- iTerm.app ----------------------------------
-- script: Clear terminal contents & Go to indicated directory
-- by: Kniazidis Robert, Greece
-- date: 5 Apr 2020
--------------------------------------------------------------------------------------

tell application "Finder"
   if exists Finder window 1 then
       set currentFolder to target of Finder window 1 as alias
       set currentFolderPath to quoted form of POSIX path of currentFolder
   else
       return
   end if
end tell

tell application "iTerm" -- wait until window "zsh" appears as frontmost
   activate
   repeat until window "zsh" exists
       delay 0.02
   end repeat
end tell

-- go to current location
tell application "System Events" to keystroke "cd " & currentFolderPath & return

-- wait while current session of current tab of window of iTerm is busy (changes current directory)
tell application "iTerm" to tell current session of current tab of window "zsh"
   repeat while (is processing) is true
       delay 0.02
   end repeat
end tell

-- clear all window contents, except the last line
tell application "System Events" to keystroke "k" using command down

NOTE:
Although iTerms is preferable to use with zsh shell as default, you can use it when the current account has bash shell as default too. In this case you can use the same script, replacing the name of window "zsh" with "bash".

Last edited by KniazidisR (2020-04-11 06:41:02 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2020-04-07 06:01:07 am

Danjuan
Member
Registered: 2020-04-02
Posts: 14

Re: error "iTerm got an error: TERM environment variable not set."

Thanks everyone

Works perfect.

Offline

 

#6 2020-04-11 05:36:09 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: error "iTerm got an error: TERM environment variable not set."

I find today none GUI-scripting solution (used command write text, similar to do script of Terminal.app):

Applescript:


----------------------------------- iTerm2.app ----------------------------------
-- script: Clear terminal contents & Go to indicated directory
-- by: Kniazidis Robert, Greece
-- updated: 11 Apr 2020
--------------------------------------------------------------------------------------

tell application "Finder"
   if not (exists Finder window 1) then return
   set currentFolder to target of Finder window 1 as alias
end tell

tell application "iTerm"
   activate
   repeat until window 1 exists
       delay 0.02
   end repeat
   tell current session of current tab of window 1
       write text "cd " & quoted form of POSIX path of currentFolder & ";clear"
   end tell
end tell

Last edited by KniazidisR (2020-04-12 07:06:48 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)