简体   繁体   English

用bash -c运行osascript

[英]Running osascript with bash -c

I'm working on a Sublime Text plugin (Python) and I have some shell scripts that are a part of it. 我正在开发Sublime Text插件(​​Python),并且其中包含一些shell脚本。 Since Package Control gives you zipped packages, these scripts can't be run as files from within the zip, so I'm storing them as strings and running them with subprocess.Popen and bash -c. 由于Package Control为您提供了压缩的软件包,因此这些脚本不能作为zip中的文件运行,因此我将它们存储为字符串,并使用subprocess.Popen和bash -c运行它们。 The Mac version of the script requires osascript, which I'm having trouble running from a string. Mac版本的脚本需要osascript,我无法从字符串运行它。 The osascript part of the script is as follows (everything before it works fine): 脚本的osascript部分如下所示(一切正常运行之前):

osascript <<END
    tell application "Terminal"
        tell window 1
            activate
            set w to do script "clear; bash -c \"ssh -t $simulator_user@$simulator_host '$token $build_args'; echo; echo Press any key to continue; read -n 1; exit\""
        end tell
    end tell
END

I've so far successfully implemented the first activate statement with osascript -e 'tell application "Terminal" to tell window 1 to activate'; 我到目前为止已经成功地实现了第一个activate with语句osascript -e 'tell application "Terminal" to tell window 1 to activate'; but the second statement is giving me a lot of trouble, mostly due to all the quotes. 但是第二句话给我带来了很多麻烦,这主要是由于所有引号引起的。 I've been using the Python """triple quote""" format for my strings. 我一直在使用Python的"""triple quote"""格式作为字符串。 The farthest I've gotten is something like 我走得最远的是

script = """"clear; bash -c "ssh -t $simulator_user@$simulator_host '$token $build_args'; echo; echo Press any key to continue; read -n 1; exit"\""""
darwin_osa2 = """osascript -e 'tell application "Terminal" to tell window 1 to set w to do script {}';""".format(script)

but I'm getting things like "83:87: syntax error: A identifier can't go after this “"”. 但我收到类似“ 83:87:语法错误:标识符不能在此””后面的信息。 (-2740)" and other equally nonspecific errors. Does anyone know the correct way to format that second statement for use with bash -c (or better yet, an easier way to run it)? (-2740)”和其他同样非特定的错误。有人知道格式化第二条语句以与bash -c一起使用的正确方法(或者更好的方法是运行它的更简便方法)?

You can create the file .no-sublime-package and Package Control will extract the zipped package. 您可以创建文件.no-sublime-package然后Package Control将解压缩压缩的软件包。 That way you can add scripts and execute them. 这样,您可以添加脚本并执行它们。

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

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