mac终端:定位于当前文件夹位置Terminal设置快捷键,实现快速启动--m系列

mac自动脚本(f3直接搜或者找其他->自动操作)

然后找到如下功能:

代码如下: 

on run {input, parameters}  
    tell application "Finder"  
        set currFolder to POSIX path of (folder of the front window as string)  
    end tell  
    tell application "Terminal"  
        do script ("cd " & "'" & currFolder & "'")  
    end tell  
end run

但是,这无法让终端显示在最前方,窗口在后面,需要再次点击程序坞才能聚焦到,那就需要优化一下功能了,新代码如下:

tell application "Finder"
	-- 获取当前 Finder 窗口中的文件夹路径  
	set folderPath to POSIX path of (folder of the front window as alias)
end tell

-- 构建要在 Terminal 中执行的命令  
set terminalCommand to "cd '" & quoted form of folderPath & "'; pwd"

-- 告诉 Terminal 应用执行命令  
tell application "Terminal"
	-- 尝试激活 Terminal 应用(但这不保证窗口会出现在最前面)  
	activate
end tell

保存,命名好你想要取得名字,然后进入“系统偏好设置” > “键盘” > “快捷键” > “服务”中,找到"通用",里面有你命名好的文件名,双击设置快捷键并打勾即可。

嗯,这下可以了,免去了花钱买某些软件还经常报错失败的问题。

注意:

需要确定好该快捷键是没有被占用的,如果使用后不起作用说明被占用了,换一个快捷键并设置即可。

相关推荐

  1. mac 系统中vscode 返回上一次文件编辑位置快捷键

    2024-06-16 18:12:05       40 阅读
  2. vscode 系列文章目录 - 终端定义快捷键配置

    2024-06-16 18:12:05       22 阅读
  3. Rust 的 termion 库控制终端光标的位置

    2024-06-16 18:12:05       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-16 18:12:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-16 18:12:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-16 18:12:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-16 18:12:05       20 阅读

热门阅读

  1. cmake target_include_directories 详解

    2024-06-16 18:12:05       6 阅读
  2. 2024年6月四六级考试复盘

    2024-06-16 18:12:05       10 阅读
  3. flink学习-容错机制

    2024-06-16 18:12:05       6 阅读
  4. netty-reacter写一个http服务器

    2024-06-16 18:12:05       8 阅读
  5. Spring多数据源管理方案

    2024-06-16 18:12:05       8 阅读
  6. Web前端行距代码:深入探索与实战应用

    2024-06-16 18:12:05       10 阅读
  7. 介绍一个 SpringBoot 集成各种场景的项目

    2024-06-16 18:12:05       9 阅读
  8. 外包公司泛滥,这些常识你应该提前知道?

    2024-06-16 18:12:05       6 阅读