美文网首页
AppleScript实现复制路径、从这里启动

AppleScript实现复制路径、从这里启动

作者: 十一岁的加重 | 来源:发表于2018-06-26 21:50 被阅读36次

平时比较喜欢使用XtraFinder,有几个功能(标签页、拷贝路径、从这里启动、新建文件、显示与隐藏、返回上级目录)实在太方便,但是后面系统升级了,发现装了它,Finder老是有问题,卡死,得重启Finder
所以我们得自己用AppleScript做服务放右键菜单自己实现

image.png

复制路径

tell application "Finder" to set selectedItems to selection as alias list
-- 没选择的话直接退出脚本
if selectedItems is {} then return
-- 获得所选文件/文件夹的父目录。
set parentPath to do shell script "dirname " & quoted form of POSIX path of (item 1 of selectedItems)
-- 用于拼接多个路径
set pathData to ""

-- 历遍选择的项目
repeat with theItem in selectedItems
    set pathData to pathData & POSIX path of theItem & linefeed
end repeat

-- 发送到剪贴板
set the clipboard to pathData

从这里启动在上面的基础上调用了cd命令

tell application "Finder" to set selectedItems to selection as alias list
-- 没选择的话直接退出脚本
if selectedItems is {} then return
-- 获得所选文件/文件夹的父目录。
set parentPath to do shell script "dirname " & quoted form of POSIX path of (item 1 of selectedItems)
-- 用于拼接多个路径
set pathData to ""

-- 历遍选择的项目
repeat with theItem in selectedItems
    -- 如果是目录
    if (isDirectory(theItem)) then
        --如果是目录,我们就直接用这个目录
        set pathData to pathData & POSIX path of theItem & linefeed
        -- 把目录最后面的那个/字符去掉
        set pathData to text 1 thru -2 of pathData
    else
        -- 如果是文件我们就拿到上一级的目录
        set pathData to pathData & POSIX path of theItem & linefeed
        set pathData to characters 1 thru -((offset of "/" in (reverse of items of pathData as string)) + 1) of pathData as string
        
        -- 下面两句获得各个文件的文件名(文件夹的话获取文件夹名),并换行拼接
        --set fileName to do shell script "basename " & quoted form of POSIX path of theItem
        --set pathData to pathData & fileName & linefeed
    end if
end repeat

-- 发送到剪贴板
--set the clipboard to pathData
tell application "Terminal"
    do script "cd " & pathData & "; clear;"
    tell application "System Events"
        tell process "Terminal"
            
            set frontmost to true
            
        end tell
    end tell
end tell

---------------------------------------------------------
on isDirectory(someItem)
    set filePosixPath to quoted form of (POSIX path of someItem)
    set fileType to (do shell script "file -b " & filePosixPath)
    if fileType ends with "directory" then return true
    return false
end isDirectory

相关文章

  • AppleScript实现复制路径、从这里启动

    平时比较喜欢使用XtraFinder,有几个功能(标签页、拷贝路径、从这里启动、新建文件、显示与隐藏、返回上级目录...

  • AppleScript 编程

    AppleScript的字典怎么看怎么用AppleScript 操作Mac路径AppleScriptAppleSc...

  • Go2Shell and AppleScript

    Go2Shell and AppleScript 给Finder加上一个打开当前路径的终端的功能 有两种实现:Go...

  • 多机数据库的实现

    多机数据库的实现 复制 启动主从的方式是 SLAVEOF 127.0.0.1 6379(主库地址) 复制功能的实现...

  • 2018-09-27【如何写服务自启】

    1.例子:如何给java服务实现自启动。解决机器重启后保持服务正常。获取java服务的路径 2.编写启动脚本这里可...

  • docker修改镜像存储目录

    停止docker服务 修改服务配置 增加启动参数 -g 文件路径 复制文件到新目录 重新加载服务配置 启动doc...

  • Put Object Copy文档

    Put Object Copy 功能描述 Put Object Copy 请求实现将一个文件从源路径复制到目标路...

  • iOS PCH

    1 创建文件 2 复制PCH地址,从 项目名称后面进行复制 搜索路径 4 添加路径把之前的路径添加进去 $(SRC...

  • 初识AppleScript

    字符集 从OS X v10.5(AppleScript 2.0)开始, AppleScript的字符集是Unico...

  • HBuilderX无法启动微信小程序?请看步骤

    1.复制微信开发者工具启动路径 : "C:\Program Files (x86)\Tencent\微信web开发...

网友评论

      本文标题:AppleScript实现复制路径、从这里启动

      本文链接:https://www.haomeiwen.com/subject/vuqvyftx.html