Imported from the Apple Support Forums via the Wayback Machine 🔗
I was hoping for some advice. I'm a newbie and am trying to write a script that detects if a file exists and if it does, replace it with a new one. I've been reading and everything i have in the script seems right but I still keep getting an error message. Anyone know what it is?
my script try tell application "Finder" make new Finder window to alias ":Library:Desktop Pictures:" set theNewFile to POSIX file "/Storage/Deployment/Pictures/DefaultDesktop.jpg" set theFolder to folder "/Library/Desktop Pictures/" as string set theCorrectpath to POSIX path of theFolder set theOldFile to POSIX file "/Library/Desktop Pictures/DefaultDesktop.jpg" if (theOldFile) exists then delete theOldFile move the theNewFile to theCorrectpath
else move the theNewFile to theCorrectpath
end if end tell end try
the error: tell application "Finder" make new Finder window to alias "Macintosh HD:Library:Desktop Pictures:" --> Finder window id 333 get folder "/Library/Desktop Pictures/" --> error number -1728 from folder "/Library/Desktop Pictures/" end tell
Imported from the Apple Support Forums via the Wayback Machine 🔗
Try using:
try tell application "Finder" make new Finder window to alias ":Library:Desktop Pictures:" set theNewFile to POSIX file "/Storage/Deployment/Pictures/DefaultDesktop.jpg" set theCorrectpath to "/Library/Desktop Pictures/" set theOldFile to POSIX file "/Library/Desktop Pictures/DefaultDesktop.jpg" if theOldFile exists then delete theOldFile move the theNewFile to theCorrectpath else move the theNewFile to theCorrectpath end if end tell end try
(51600)
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Almost. The error has changed. It looks like you took off "as string" on set theFolder line?
I'm now getting the following error: tell application "Finder" make new Finder window to alias "Macintosh HD:Library:Desktop Pictures:" --> Finder window id 355 exists file "Macintosh HD:Library:Desktop Pictures:DefaultDesktop.jpg" --> false move file "Macintosh HD:Storage:Deployment:Pictures:DefaultDesktop.jpg" to "/Library/Desktop Pictures/" --> error number -1700 from "/Library/Desktop Pictures/" to folder end tell
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
BTW, awesome response time! I thought I was going to have to sit on this project for awhile.
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
maybe this will help...
try set GoodCopy to "/Storage/Deployment/Pictures/DefaultDesktop.jpg" set CurrentCopy to "/Library/Desktop Pictures/DefaultDesktop.jpg" set CurrentCopy to ((POSIX file CurrentCopy) as alias) set GoodCopy to ((POSIX file GoodCopy) as alias) tell application "Finder" to move GoodCopy to container of CurrentCopy with replacing on error tell me activate display dialog "It appears there isn't an image file in the "Pictures" folder named DefaultDesktop.jpg." buttons {"OK"} ¬ cancel button 1 default button 1 with title "Error" end tell end try
Message was edited by: Tom_X
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
After much head scratching, I ended up with something similar. I was leaving off "POSIX" which was causing the main issue.
tell application "Finder" try set theNewfile to POSIX file "pathtofile" as alias set theFolder to POSIX file "pathtofolder"
duplicate theNewfile to theFolder with replacing
on error themessage log "this error occurred:" & themessage end try end tell