I’m trying to make a script that write text in a file and then duplicates it somewhere else. I get this :
tell application "Finder" to get folder of (path to me) as Unicode text
set workingDir to POSIX path of result
set theFile to workingDir & "file.txt"
set theText to "Some text..."
set theFileReference to open for access theFile with write permission
write theText to theFileReference
close access theFileReference
tell application "Finder" to duplicate theFile to "Macintosh HD:Applications:Microsoft Office 2011:Office:Startup:Word:" with replacing
but I always get the error :
error "Finder got an error: Can’t make \"/Users/ME/Documents/file.txt\" into type item."
and the weirdest thing is that I do a duplicate just above that that works…but it is basically the same thing.
I start with Applescript so I would not be surprise it’s a stupid little detail…So any clue is appreciated!
The Finder doesn’t know what POSIX paths are. You can coerce your file path, for example
(theFile as POSIX file), or you can use System Events.