I'm working on a Sublime Text plugin (Python) and I have some shell scripts that are a part of it. 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. The Mac version of the script requires osascript, which I'm having trouble running from a string. The osascript part of the script is as follows (everything before it works fine):
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';
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. 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 “"”. (-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)?
You can create the file .no-sublime-package
and Package Control will extract the zipped package. That way you can add scripts and execute them.