预览

时间:2018-03-29 15:03:33

标签: applescript preview

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

目前,我正在使用

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

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

非常感谢

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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