bash applescript 和终端(在一个终端窗口中运行多个 do shell 脚本)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13090235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:39:12  来源:igfitidea点击:

applescript and terminal ( run several do shell script in one terminal window )

bashshellapplescript

提问by Lord iPhonius

I do have several shell scripts whom are get activate not really behind each other.

我确实有几个 shell 脚本,它们被激活并没有真正相互落后。

But I want to stay in the same terminal window.

但我想留在同一个终端窗口。

To simplify the problem, lets say that as example

为了简化问题,让我们举个例子

first script. - cd to the working directory second. - do some things and get files from that directory third. - dome more thing on the newly files/folders in that directory. fourth. - ....

第一个脚本。- cd 到第二个工作目录。- 做一些事情并从第三个目录中获取文件。- 在该目录中的新文件/文件夹上做更多事情。第四。- ....

How can I let script 2 and 3 ( all the script thus ) run in that very same directory and window that is opened during script 1?

如何让脚本 2 和 3(因此所有脚本)在脚本 1 期间打开的相同目录和窗口中运行?

F.e how can I avoid using the full path to that folder for every file.

Fe 如何避免为每个文件使用该文件夹的完整路径。

EDIT: After adayzdone's answer I realize that I forgot to mention that I need also administrator privileges for one of the scripts

编辑:在 adayzdone 的回答之后,我意识到我忘了提到我还需要其中一个脚本的管理员权限

EDIT2: For now I use this

EDIT2:现在我用这个

tell application "Terminal"
    set newTab to do script
    set current settings of newTab to settings set "Grass"
    do script "bin/sh/ echo 'xx' | su;" in newTab
    do script "cd " & quoted form of realParentPath in newTab
    do script shellscript1 in newTab
    do script shellscript..n in newTab
    activate
end tell

but still no dice with the privileges.

但仍然没有具有特权的骰子。

回答by adayzdone

try:

尝试:

tell application "Terminal"
    do script "cd ~/" in window 1
    do script "ls -a" in window 1
end tell

OR

或者

property usr : "username"
property pswd : "password"

set xxx to do shell script "cd ~/ ; ls -a " user name usr password pswd with administrator privileges