预览中所选图像的 Applescript 副本名称

Applescript copy name of selected image in preview

我在一个预览中打开了几张图片 window。我正在尝试复制 window 中所选图像的文件名。

目前,我正在使用

tell application "Preview" to activate
tell application "System Events" to keystroke "c" using command down

这不起作用,可能是因为它复制了文件及其路径(我只需要文件名作为字符串)

非常感谢

也许这正是您要查找的内容?

tell application "Preview"
    set thePath to path of document of front window as POSIX file as alias
end tell
tell application "Finder"
    set theName to name of (get properties of thePath)
end tell
set the clipboard to theName
    set the text item delimiters to "/"

    get the path of the front document in application "Preview"
        --> "/Users/CK/Pictures/Screenshots/Screen Shot 2018-03-29 at 16.06.jpg"
    get the last text item of the result
        --> "Screen Shot 2018-03-29 at 16.06.jpg"


    --OR--


    get the path of the front document in application "Preview"
    tell application "System Events" to get the name of the file result
        --> "Screen Shot 2018-03-29 at 16.06.jpg"


    --THEN--


    set the clipboard to the result