applescript剪贴板图片来浏览目录

时间:2013-10-01 11:32:49

标签: image file applescript clipboard

请帮助编辑此脚本以选择mannualy dir文件正在保存的位置,并且可以手动输入名称以节省文件。

的问候。

这是有效的工具,只需将内容从剪贴板保存到桌面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

1 个答案:

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