首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >复制/粘贴文件/文件夹路径名的工作不一致

复制/粘贴文件/文件夹路径名的工作不一致
EN

Stack Overflow用户
提问于 2022-10-28 15:42:26
回答 1查看 43关注 0票数 0

我有一个使用shell脚本的Automator服务,我正在使用键盘快捷方式将文件/文件夹路径名复制到剪贴板。该服务在Finder应用程序中接收选定的文件或文件夹,并将它们作为参数传递给以下shell脚本。

代码语言:javascript
复制
for f in ”$@”
do
echo \""$f"\"
# also tried it with "\"$f\""
done

这将输出到一个copy to clipboard操作。当粘贴到文本编辑器、Finder的搜索框等中时,它工作得很好。

但是,我还有一个通过QuicKeys运行的条件脚本,它允许我在一个名为“收割”的音频应用程序中,将文本粘贴到各个窗口的某些有问题的文本字段中(否则,粘贴文本的快捷方式⌘+v根本不起作用)。奇怪的是,如果我从Finder复制路径名,将其粘贴到文本编辑器中,选择它,然后复制它,那么粘贴复制文本的脚本在“收割器”中工作得很好。但是,直接从Finder复制路径名到剪贴板,然后尝试将其粘贴到“收割器”中的文本字段中是行不通的。

下面是我用QuicKeys快捷方式调用的applescript。

代码语言:javascript
复制
global frontApp, frontAppName, windowTitle, seltxt
set windowTitle to ""

tell application "System Events"
    set frontApp to first application process whose frontmost is true
    set frontAppName to name of frontApp
    tell process frontAppName
        tell (first window whose value of attribute "AXMain" is true)
            set windowTitle to value of attribute "AXTitle"
        end tell
    end tell
end tell

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

set RprRunning to is_running("REAPER")

try
    if RprRunning then
        tell application "System Events"
            if exists (window "Save" of process "REAPER") then
                tell text field "Save As:" of window "Save" of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
                tell text field "Save As:" of window "Save" of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
                
            else if exists text field 6 of window windowTitle of application process "REAPER" then
                tell sixth text field of window windowTitle of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
                tell sixth text field of window windowTitle of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
                
            else if exists (text field 2 of window windowTitle of application process "REAPER") then
                tell second text field of window windowTitle of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
                tell second text field of window windowTitle of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
                
            else if exists (text field 1 of window windowTitle of application process "REAPER") then
                tell first text field of window windowTitle of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
                tell first text field of window windowTitle of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
    
            end if
        end tell
        return seltxt
    end if
end try

我真的很想让这件事正常运作。我一直在绞尽脑汁想弄清楚为什么复制的文件/文件夹路径名需要粘贴到“收割器”之外的某个文本字段中,然后才能粘贴到“收割器”中的文本字段中。

EN

回答 1

Stack Overflow用户

发布于 2022-10-28 16:03:50

嗯,我不确定其中一个脚本是否还有什么需要修复的地方。但就目前而言,我似乎无意中找到了解决办法。

我没有将shell脚本的输出直接传递到copy to clipboard操作,而是在它之前添加了一个filter paragraphs操作,并将其设置为return paragraphs that: begin with: "

这似乎与粘贴和复制“收割器”外的文本字段中的路径名称字符串具有相同的效果,而且在从Finder中的选定文件/文件夹中复制路径名之后,我现在能够将路径名直接粘贴到“收割器”中的文本字段中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74237762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档