AppleScript打开终端,运行命令并显示-无法正常工作 [英] Applescript to open terminal, run command, and show - Not working

查看:377
本文介绍了AppleScript打开终端,运行命令并显示-无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个快捷键来打开当前文件夹中的终端.环顾四周,我发现此代码创建了一个服务(解决了向该服务添加快捷方式的部分),仅添加的内容是; clear"和一些"activate",因此它显示了

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 is solved), only added things are the "; clear" and some of the "activate" so it shows

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(文件夹)上选择一个项目,它将打开其父目录,而我会 喜欢它来打开选定的文件夹
  • it opens two windows in terminal, have no idea why. It has nothing to do with the added "activate"… it has always donde that
  • if I select an item on finder ( a folder ) it opens its parent directory and i would like it to open the selected folder

这是我第一次尝试使用Applescript,因此如果错误很明显我就看不到

this is my very first try with Applescript so if the error is obvious i just can't see it

预先感谢

推荐答案

do script命令已经在Terminal中打开了一个窗口.尝试这种方式:

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

这篇关于AppleScript打开终端,运行命令并显示-无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆