0

I'm new to Python and trying to automate a process on my computer, but I'm having trouble. I've already written my Python script with what I want to print, but I'd like to have my own code to press enter after that. I tried "keyboard.press(Key.enter)," but my code does not run on the terminal.

Here is the code:

from pynput.keyboard import Key, Controller

keyboard = Controller()

print(''"export SPOTIPY_CLIENT_ID='123'"'')
print(''"export SPOTIPY_CLIENT_SECRET='123'"'')

keyboard.press(Key.enter)
keyboard.release(Key.enter)
#suppose to press return


print('savify "https://open.spotify.com/playlist/37i9dQZEVXbMDoHDwVN2tF?si=eac8b42e32934a6c" -q best -f mp3 -o "/Users/" -g "%artist%/%album%"')

keyboard.press(Key.enter)
keyboard.release(Key.enter)
#suppose to press return

I expected it to run my program but it just goes to the other line.

2
  • why do you want to press enter? just run the script using a scheduler like task scheduler or cron depending on the OS you are using, I'm hoping you would do some more tasks apart from print Commented Nov 5, 2022 at 5:22
  • Not sure exactly what it is, but it looks like you're trying to run some Spotify command in the CLI. If your commands are right (I'm talking about the strings), then you shouldn't print them, instead type or return them. Commented Nov 5, 2022 at 5:23

1 Answer 1

1

I understood your problem, don't print those commands, instead go to the CLI tab and type them.

import pyautogui as gui
import time

time.sleep(5) # Time you should take to switch to the command line tab on foreground

gui.write("export SPOTIPY_CLIENT_ID='123'")
gui.write("export SPOTIPY_CLIENT_SECRET='123'")

gui.press('enter')
#suppose to press return

gui.write('savify "https://open.spotify.com/playlist/37i9dQZEVXbMDoHDwVN2tF?si=eac8b42e32934a6c" -q best -f mp3 -o "/Users/" -g "%artist%/%album%"')

gui.press('enter')
#suppose to press return
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.