簡體   English   中英

使用 applescript 將多個 POSIX 文件復制到剪貼板

[英]Copy multiple POSIX files to clipboard with applescript

我正在嘗試將多個文件復制到 macOS 中的剪貼板,如下所示:

./file2clip.applescript /User/Cool/Dekstop/test.txt /User/Cool/Dekstop/myfolder

我已經可以只用一個文件來做到這一點:

#!/usr/bin/osascript
on run args
    set the clipboard to POSIX file (first item of args)
end

但它只適用於一個文件......

我試過這個

on run args
    set the clipboard to POSIX files args
end

但它沒有用。

還有這個

on run args
    set pathList to {}
    repeat with arg in args
        set end of pathList to POSIX file arg
    end repeat
    set the clipboard to pathList
end

但這也沒有用

將所有 POSIX 文件添加到字符串中也不起作用,因為剪貼板中只有文本,所以我無法使用ctrl + v粘貼所有文件,我只能粘貼它們的名稱。 不是我想要達到的。

property files: ""

on run args
    repeat with f in args
        set files to files & POSIX file f & "\n"
    end repeat
    set the clipboard to files
end

有任何想法嗎?

在您的原始片段中,將剪貼板設置為第一個參數項是有效的,因為它是文本。 將剪貼板設置為列表似乎失敗,因為它是一個列表- 數據在那里,它與文本的工作方式不同( clipboard info可用於獲取有關剪貼板上項目的信息)。

從命令行中,arguments(根據需要引用和/或轉義)應該已經作為 POSIX 路徑列表傳遞給腳本,但也可以根據需要執行強制和/或操作,例如波浪號擴展。 可以使用常規文本操作將各個項目放置到剪貼板上,但是您希望使用常規文本操作 - 例如,要將 arguments 與返回分開,您可以執行以下操作:

on run args
    set pathString to ""
    repeat with arg in args
        set pathString to pathString & arg & return
    end repeat
    set the clipboard to pathString
end run

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM