PDA

View Full Version : Applecript n00b, please help




GoaTrancer
Feb 20, 2012, 01:56 PM
I have written the following script. I get no errors when I test it, yet nothing happens when I run it

try



tell application "Finder"
move file "/Users/alexk/synctest/Untitled3.rtf" to folder "/Users/alexk/Dropbox/nupdftest"


end tell
end try

I have tried a couple other things in place of duplicate (copy, move), yet no matter what, after running the script I do not find the file in the target folder, "nupdftest"

Edit: the error I get back is "error number -1728 from file "/Users/alexk/synctest/Untitled3.rtf"
I'm googling around to find out what that means in this context but not having a lot of luck. That path is absolutely correct, I double and triple checked.

Any ideas what is going wrong here?
Apologies in advance for what is probably a dumb question.. but I've googled around and can't figure out what's bad about my script.
PS in case you are wondering why I've made such a pointless script, it's just part of process of figuring out why a different script wasn't working, I just simplified it to eliminate sources of error.



Red Menace
Feb 20, 2012, 02:39 PM
The Finder doesn't know about POSIX paths, it uses the colon delimited HFS paths. You can coerce to POSIX files, or use System Events.

GoaTrancer
Feb 20, 2012, 02:51 PM
Great, that solved it, my script now works as intended. Thanks!

hadirajan
Feb 21, 2012, 04:32 PM
How would the script look if I wanted to move all files in a specific folder?

Red Menace
Feb 21, 2012, 04:42 PM
That would be move entire contents of ...

r0k
Feb 21, 2012, 05:10 PM
How would the script look if I wanted to move all files in a specific folder?

try



tell application "Finder"
move (files of folder ":Users:alexk:synctest:" whose name does not start with ".") to (":Users:alexk: Dropbox:nupdftest")


end tell
end try

I had to give a partial filename because if you run this without any file name, it starts by trying to move . and .. which of course can't be moved and you get error -17 somethingorother.