applescript and terminal ( run several do shell sc

2019-05-10 03:17发布

问题:

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