Demo entry 6687637

Screenshot Clipoard


Submitted by Adriannier on Dec 30, 2017 at 05:46
Language: AppleScript. Code size: 1.5 kB.

-- Generate pseudorandom numbers
    set rand1 to (round (random number from 100 to 999)) as text
    set rand2 to (round (random number from 100 to 999)) as text
    set randomText to rand1 & "-" & rand2
    -- Create file name
    set fileName to (("AppleScriptTempFile_" & randomText) as text)
    -- Get the path to the parent folder
    set temporaryFolderPath to (path to temporary items folder from user domain) as text
    if folderName is false then
        set parentFolderPath to temporaryFolderPath
        -- Create parent folder if necessary
        set parentFolderPath to temporaryFolderPath & folderName & ":"
        tell application "System Events"
            if (exists folder parentFolderPath) is false then
                make new folder at the end of folders of folder temporaryFolderPath with properties {name:folderName}
            end if
        end tell
    end if
    -- Make sure the file does not exist
    set rNumber to 1
        if rNumber is 1 then
            set tempFilePath to parentFolderPath & fileName
            set tempFilePath to parentFolderPath & fileName & "_" & (rNumber as text)
        end if
        tell application "System Events" to if (exists file tempFilePath) is false then exit repeat
        set rNumber to rNumber + 1
    end repeat
    return tempFilePath
end temporaryPathWithFolderName

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).