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

问题描述 投票:1回答:2

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

目前,我正在使用

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

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

非常感谢

applescript preview
2个回答
1
投票

也许这与您所寻找的一致?

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

0
投票
    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
© www.soinside.com 2019 - 2024. All rights reserved.