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

后端 未结 2 955
春和景丽
春和景丽 2020-12-31 23:32

I´m trying to create a keyshortcut to open terminal in current folder. Looking around, I found this code to create a service (the part of adding the shortcut to this service

相关标签:
2条回答
  • 2020-12-31 23:55

    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
    
    0 讨论(0)
  • 2021-01-01 00:11

    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
    
    0 讨论(0)
提交回复
热议问题