繁体   English   中英

Applescript 打开终端、运行命令和显示 - 不工作

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

我正在尝试创建一个快捷键来打开当前文件夹中的终端。 环顾四周,发现这段代码创建了一个服务(给这个服务添加快捷方式的部分解决了),只是添加的东西是“;清除”和一些“激活”所以它显示

on run {input, parameters}

tell application "Finder"
    activate

    set myWin to window 1

    set theWin to (quoted form of POSIX path of (target of myWin as alias))

    tell application "Terminal"

        activate
        tell window 1
            activate
            do script "cd " & theWin & ";clear"
        end tell

    end tell

end tell


return input

end run

它不像我想要的那样工作。

麻烦:

  • 它在终端打开两个窗口,不知道为什么。 它与添加的“激活”无关……它一直不知道
  • 如果我在 finder(一个文件夹)上选择一个项目,它会打开它的父目录,我希望它打开选定的文件夹

这是我第一次尝试 Applescript 所以如果错误很明显我就是看不到它

提前致谢

do script命令已经在终端中打开了一个窗口。 试试这个方法:

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

我更喜欢重新打开方法...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM