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

标签 applescript automator

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

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
    

    关于Applescript 打开终端、运行命令和显示 - 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23975239/

    相关文章:

    cocoa :如何创建新的SBElementArray?

    shell - Automator 用苹果脚本或 shell 脚本替换字符

    macos - 使用 AppleScript 拆分全屏应用程序

    linux - 从 bash 脚本中执行 applescript 获取输出

    qt - applescript-QuickTime 7音频(WAV)导出

    applescript - 我可以从 iWork 应用程序中的菜单或热键执行 Applescript 吗?

    javascript - Automator Javascript - "Choose From List"返回值

    objective-c - 确定窗口是否被拖动

    python - 如何查看在 automator 中运行的脚本的标准输出

    applescript - Automator Apple 脚本转换 jpeg 图像