简体   繁体   English

如何在终端中原子运行命令?

[英]How to run in atom a command in the terminal?

I'm doing a school project about changing my wallpaper from python and it works in the terminal perfectly but I need to do it from my text editor, atom, and it doesn't seem to work. 我正在做一个关于从python更改壁纸的学校项目,它可以在终端中正常运行,但是我需要通过文本编辑器atom来完成它,但似乎不起作用。 I've tried rearranging the apostrophes as maybe it's that, but can't seem to make it work. 我已经尝试过重新排列撇号,但似乎无法使其正常工作。

This works on the terminal perfectly: 可以完美地在终端上运行:

osascript -e 'tell application "System Events" to set picture of every desktop to ("/Users/carlaa/Desktop/DEVf/python/APODkata/apodimage.jpg" as POSIX file as alias)'

but from atom in says invalid syntax 但是从原子中说无效的语法

from subprocess import call
subprocess.call(["osascript -e 'tell application "System Events" to set picture of every desktop to ("/Users/carlaa/Desktop/DEVf/python/APODkata/apodimage.jpg" as POSIX file as alias)'",shell=True])

You need to escape those double quotes and remove subprocess : 您需要转义那些双引号并删除subprocess

from subprocess import call
call(["osascript -e 'tell application \"System Events\" to set picture of every desktop to (\"/Users/carlaa/Desktop/DEVf/python/APODkata/apodimage.jpg\" as POSIX file as alias)'", shell=True])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM