Applescript to open terminal, run command, and show - Not working

寵の児 提交于 2019-11-30 09:55:41

The do script command already opens a window in Terminal. Try it this way:

tell application "Finder" to set theSel to selection

tell application "Terminal"
 set theFol to POSIX path of ((item 1 of theSel) as text)
 if (count of windows) is not 0 then
  do script "cd " & quoted form of theFol & ";clear" in window 1
 else
  do script "cd " & quoted form of theFol & ";clear"
 end if
 activate
end tell

I like the reopen approach better...

tell application "Finder" to set currentFolder to target of front Finder window as text
set theWin to currentFolder's POSIX path

tell application "Terminal"
    if not (exists window 1) then reopen
    activate
    do script "cd " & quoted form of theWin & ";clear" in window 1
end tell
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!