AppleScript复制名称在预览中所选图像的名称



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

目前,我正在使用

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

最新更新