0

I created a Python script that uses the Todoist API to export my task list to a list of strings (I want to paste them as Discord messages) and it works fine if I run the command on the Terminal window, but if I run the same command using AppleScript, an error is thrown, saying No module named todoist.api. Here's the code: (I have only one line)

do shell script "$HOME/tasks.sh"

The shell scripts runs the python scripts I need, but the problem is in the imports of those files, which are:

from datetime import date, datetime, timedelta
from todoist.api import TodoistAPI
import pyperclip
import os
import MyTodoist

in the first file (tasks.py) and

from datetime import date, datetime, timedelta
from todoist.api import TodoistAPI
import pyperclip
import os

in the second file (MyTodoist.py) The final goal is to store the result of a function in tasks.py in a variable in my script, but I don't know how. Can someone help me please?

  • 1
    `do shell script` does not automatically read your bash/zsh profile, so you may need to define Python-related environment variables yourself. – foo Nov 26 '20 at 08:34
  • @foo okay, how do I do it? I'm still new to AppleScript... – Clarissa De Simoni Nov 26 '20 at 14:16
  • 2
    That’s really a shell/Python question. IIRC `do shell script` runs [ba]sh itself, so you’d define a new environment variable using `export NAME=VALUE`, e.g. `export PYTHONPATH=/some/path:/another/path; rest-of-your-commands`. Depends on how your shell, Python,etc are configured on your own machine. Running `env` in Terminal will list all the environment variables defined there, which may help you work out which ones to include. [This](https://developer.apple.com/library/archive/technotes/tn2065/_index.html) may also be helpful. – foo Nov 27 '20 at 09:09
  • @foo thank you! The link seems really helpful, I'll check it out right away! – Clarissa De Simoni Nov 27 '20 at 17:01

0 Answers0