1

请帮助编辑此脚本,以便可以手动选择文件保存的目录,并且可以手动输入保存文件的名称。

问候。

这是有效的applescript,只需将剪贴板中的内容保存到桌面ABC.jpg 文件。

       property fileTypes : {¬
    {JPEG picture, ".jpg"}, ¬
    {TIFF picture, ".tiff"}, ¬
    {GIF picture, ".gif"}, ¬
    {«class PDF », ".pdf"}, ¬
    {«class RTF », ".rtf"}}

set theType to getType()

if theType is not missing value then
    set myPath to (path to desktop folder as text) & (first item of theType) & (second item of theType)

    try
        set myFile to (open for access myPath with write permission)
        set eof myFile to 0
        write (the clipboard as (first item of theType)) to myFile -- as whatever
        close access myFile
        return (POSIX path of myPath)
    on error
        try
            close access myFile
        end try
        return ""
    end try
else
    return ""
end if

on getType()
    repeat with aType in fileTypes -- find the first match in the list
        repeat with theInfo in (clipboard info)
            if (first item of theInfo) is equal to (first item of aType) then return aType
        end repeat
    end repeat
    return missing value
end getType
4

1 回答 1

2

尝试:

property fileTypes : {¬
    {JPEG picture, ".jpg"}, ¬
    {TIFF picture, ".tiff"}, ¬
    {GIF picture, ".gif"}, ¬
    {«class PDF », ".pdf"}, ¬
    {«class RTF », ".rtf"}}

set theType to getType()

if theType is not missing value then

    --set myPath to (path to desktop folder as text) & (first item of theType) & (second item of theType)
    set myPath to choose file name
    if myPath does not end with (second item of theType) then set myPath to (myPath & second item of theType as text)

    try
        set myFile to (open for access myPath with write permission)
        set eof myFile to 0
        write (the clipboard as (first item of theType)) to myFile -- as whatever
        close access myFile
        return (POSIX path of myPath)
    on error
        try
            close access myFile
        end try
        return ""
    end try
else
    return ""
end if

on getType()
    repeat with aType in fileTypes -- find the first match in the list
        repeat with theInfo in (clipboard info)
            if (first item of theInfo) is equal to (first item of aType) then return aType
        end repeat
    end repeat
    return missing value
end getType
于 2013-10-01T13:20:57.620 回答