Search code examples
applescript

AppleScript: Duplicate file, Rename it with Seconds from Midnight and then open it


I am just starting with AppleScript and can't figure our very simple (probably) thing. I would like to duplicate specific file, then rename the duplicate to only 'seconds from midnight timestamp.indd' (to keep the naming seemingly random) and after that open it in application Adobe InDesign 2020

So far I only have the duplicate part with:

tell application "Finder"
duplicate file "Macintosh HD:Users:user:Documents:filename.indd"
end tell

Thank you for any help


Solution

  • If I understood you correctly, you need something like this:

    set theSeconds to time of (current date)
    
    tell application "Finder"
        set theDuplicate to duplicate file "Macintosh HD:Users:user:Documents:filename.indd"
        set name of theDuplicate to "" & theSeconds & ".indd"
    end tell
    
    tell application "Adobe InDesign CC 2020" to open file (theDuplicate as string)