Vitalie
Vitalie

Reputation: 37

applescript clipboard image to browse directory

Please help to edit this script to can sellect mannualy dir where the file is saving and can input mannually a name af savings file.

Regards.

This is working applescript just save content from clipboard to desktop ABC.jpg file.

       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

Upvotes: 1

Views: 812

Answers (1)

adayzdone
adayzdone

Reputation: 11238

Try:

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

Upvotes: 2

Related Questions