Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos OSX:我如何通过编程判断我';我在终端或iTerm中运行?_Macos_Terminal_Applescript_Iterm - Fatal编程技术网

Macos OSX:我如何通过编程判断我';我在终端或iTerm中运行?

Macos OSX:我如何通过编程判断我';我在终端或iTerm中运行?,macos,terminal,applescript,iterm,Macos,Terminal,Applescript,Iterm,我有一个在OSX上运行的命令行应用程序,它希望使用AppleScript在当前窗口中创建几个选项卡 如何判断我的程序是在终端、iTerm还是其他终端程序中运行 osascript -e 'tell application "Finder" to get the name of every process whose visible is true' 这将是一个正在运行的应用程序列表,假设您只运行一个终端,iTerm,…,这将起作用 用列表做你想做的 希望这有助于如果将$TERM\u程序环境变量

我有一个在OSX上运行的命令行应用程序,它希望使用AppleScript在当前窗口中创建几个选项卡

如何判断我的程序是在终端、iTerm还是其他终端程序中运行

osascript -e 'tell application "Finder" to get the name of every process whose visible is true'
这将是一个正在运行的应用程序列表,假设您只运行一个终端,iTerm,…,这将起作用

用列表做你想做的


希望这有助于如果将
$TERM\u程序
环境变量设置为
iTerm.app
Apple\u终端
,那么您可以确定要运行哪些AppleScript cmds,如果您将其作为参数传递给
osascript
(假设您使用的是
osascript

用法示例: 示例脚本:
osascript ThisScriptName.scpt $TERM_PROGRAM
--osascript ThisScriptName.scpt $TERM_PROGRAM
on run {TermType}
    if (TermType = "iTerm.app") then
        -- iTerm.app :-P
        tell application "iTerm"
            tell current window
                tell current session
                    set newSession to (split horizontally with default profile)
                end tell
            end tell
        end tell
    else if (TermType = "Apple_Terminal") then
        -- Terminal.app
        tell application "Terminal"
            do script "open 'https://iterm2.com/downloads.html'" in window 1
        end tell
    else
        -- Unknown terminal application
        return "Really? Not using iTerm.app or Terminal.app"
    end if
end run