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

回眸只為那壹抹淺笑 提交于 2019-12-07 12:21:14

问题


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

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. - ....

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?

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

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

EDIT2: For now I use this

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.


回答1:


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


来源:https://stackoverflow.com/questions/13090235/applescript-and-terminal-run-several-do-shell-script-in-one-terminal-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!