Как я могу использовать AppleScript, чтобы проверить, работает ли Python или I Python? - PullRequest
0 голосов
/ 26 января 2020

Цель :

Я пытаюсь использовать AppleScript, чтобы определить, работает ли python или ipython в Терминале.

(Для простоты , Я предполагаю, что только один из python или ipython работает.)

Проблема :

Скрипт ниже неправильно устанавливает isIPythonRunning в true когда:

  1. ipython был запущен, затем завершился, тогда
  2. python был запущен

Вопрос :

Как изменить isIPythonRunning на guish между python и ipython?

tell application "Terminal"
    activate
    set win to (get first window)
    set currentTab to (selected tab of win)
    set procs to processes of currentTab
    set proc to (end of procs)

    -- "isPythonRunning" is true regardless of whether python or ipython is running 
    set isPythonRunning to (proc is "python")

    -- "isIPythonRunning" is true if ipython is now running, or has been run then quit
    set windowName to name of win
    set isIPythonRunning to (windowName contains "ipython")

    if isIPythonRunning then
        -- this is incorrect when:
        -- IPython has been run, then quit, then python has been launched
        display dialog "IPython is running!"
    else
        display dialog "Python is running!"
    end if
end tell
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...