【问题标题】:AppleScript to open Terminal in **current** folder when clicking anywhere in Finder?在 Finder 中单击任意位置时,AppleScript 在 **current** 文件夹中打开终端?
【发布时间】:2016-08-12 23:59:29
【问题描述】:

当我右键单击 Finder 中的文件夹时,我已经拥有 New Terminal at Folder 服务。

现在我还希望能够在 Finder 窗口(即文件和文件夹周围的空白处)中右键单击 anywhere,并选择New Terminal here

我现在有以下 Automator 脚本(Run AppleScriptno input 中的 Finder):

tell application "Finder"
    set this_folder to (folder of the front Finder window) as alias
end tell

tell application "Terminal"
    activate
    do script "cd \"" & (POSIX path of (this_folder as string)) & "\""
end tell

这在我右键单击文件夹时有效 - 它会在我所在的文件夹中打开一个新的终端窗口(不是我右键单击的那个)。

现在,是否可以在右键单击空白处(或至少在文件和文件夹上)时显示此服务?

编辑

我刚刚找到了this app,它可以放置在 Finder 工具栏中,并且完全符合我的需要。但是,知道是否可以使用服务来实现仍然很有趣。

【问题讨论】:

  • 普通 AppleScript 无法检测鼠标事件,Automator 服务需要指定的 Input 才能出现在服务上下文菜单中。要获取所选文件夹的父文件夹,请写入 set this_folder to (container of folder of the front Finder window) as alias。我更喜欢工具栏的方式。

标签: macos applescript osx-elcapitan automator finder


【解决方案1】:
-- script: New Terminal at selected Folder

tell application "Finder"
    set selectedItem to item 1 of (get selection)
    set isFolder to class of selectedItem is folder
end tell

-- open selected item in the Terminal, if it is folder type
if isFolder then
    set posixPath to POSIX path of (selectedItem as alias)
    tell application "Terminal"
        activate
        set a to do script "cd " & quoted form of posixPath
    end tell
else
    display alert "Selected item is not directory"
end if

【讨论】:

    猜你喜欢
    • 2012-06-30
    • 2021-07-18
    • 2019-01-17
    • 2014-06-05
    • 2011-10-01
    • 2010-09-23
    • 2010-09-30
    • 1970-01-01
    相关资源
    最近更新 更多