|
|
#1 |
|
Prospect
Join Date: Apr 2008
Posts: 10
|
How do I "copy' a file in Applescript?
I've do a very little AppleScripting and have an script which copies a file to a burn folder. This worked fine under 10.4 with a Jon's command, but fails under 10.5.
So the question is (and it seems simple) how do I copy a file from one folder to another? |
|
|
|
|
|
#2 |
|
Hall of Famer
Join Date: Apr 2004
Posts: 2,550
|
apple-c and apple-v
|
|
|
|
|
|
#3 |
|
Hall of Famer
Join Date: Jan 2002
Posts: 2,934
|
Slow down appleman. He wants to script it!
Check out the Finder's dictionary jspitzel. In Script Editor, File -> Open Dictionary. That lists the commands for scriptable apps. In the Finder's dictionary, you'll find: duplicate v : Duplicate one or more object(s) duplicate specifier : the object(s) to duplicate [to location specifier] : the new location for the object(s) [replacing boolean] : Specifies whether or not to replace items in the destination that have the same name as items being duplicated [routing suppressed boolean] : Specifies whether or not to autoroute items (default is false). Only applies when copying to the system folder. → specifier : to the duplicated object(s) Chris Last edited by chabig; 04-17-2008 at 08:41 AM. |
|
|
|
|
|
#4 |
|
Major Leaguer
Join Date: Feb 2007
Posts: 411
|
I, personally, use shell scripts to do it. It is much quicker to use shell scripts than the Finder.
Post your sample script and I will insert and give it back
__________________
Please respond, I am desperate for human contact! |
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Jan 2002
Posts: 3,541
|
How did you think this was useful? Do you just rush to be the first reply in threads, regardless of what the person needs or wants?
__________________
COMPUTER TYPE SOME SPECIFICATIONS I COPIED FROM THE BOX STUFF I INSTALLED ALL BY MYSELF "WITTY QUOTE" |
|||||||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Jan 2002
Posts: 3,541
|
Without seeing your code, it's going to be hard for anyone to tell you why it's not working.
__________________
COMPUTER TYPE SOME SPECIFICATIONS I COPIED FROM THE BOX STUFF I INSTALLED ALL BY MYSELF "WITTY QUOTE" |
|||||||||||||||||||||||
|
|
|
|
|
#7 |
|
Prospect
Join Date: Apr 2008
Posts: 10
|
Yes - I think I'll shell script too. In fact the applescript runs a Shell Script already so I can just continue that action and bring the Applescript in to do the final burning of the CD (its a backup script).
All help appreciated. I'll probably be back shortly...... |
|
|
|
|
|
#8 | |||||||||||||||||||
|
Prospect
Join Date: Apr 2008
Posts: 10
|
OK I'm back!
The shell script seemed like such a good idea. As is often the case this turns out to be (or appears to be), a might harder. OK the problem is I want to copy a file to 'Untitled CD.fpbf' a standard burn folder (empty disk) The problem is doing a 'do script' with a space in the filename. I've looked up the Apple blurb and came up with this: (not really sure what it says!)
My do shell script has to look something like this: do shell script "cp -p "&"/Users/JS/Documents/thefile.gz"&" "&"/Users/JS/Desktop/Untitled CD.fpbf/thefile.gz" which doesn't work 'cos the 'Untitled CD' needs to be in quotes because of the space. So how do I put quotes in the do shell script? help appreciated Last edited by jspitzel; 04-18-2008 at 08:13 AM. |
|||||||||||||||||||
|
|
|
|
|
#9 |
|
Hall of Famer
Join Date: Jan 2002
Posts: 3,541
|
Your specific question is answered near the middle/end of this document, but it's worth reading it top to bottom before going further:
http://devworld.apple.com/technotes/tn2002/tn2065.html
__________________
COMPUTER TYPE SOME SPECIFICATIONS I COPIED FROM THE BOX STUFF I INSTALLED ALL BY MYSELF "WITTY QUOTE" Last edited by Mikey-San; 04-18-2008 at 09:36 AM. |
|
|
|
|
|
#10 |
|
Prospect
Join Date: Apr 2008
Posts: 10
|
Posix paths?
Call me stupid by all means - but I just don't see it.
In the example I gave (which you will note is from the Tech note quoted by you), the POSIX path is exactly what? I tried to set a variable to the POSIX path of the file for the source and destination. That seems to make sense, but then how do I do a shell script using variables? I tried: set S1 to POSIX path of file "Macintosh HD:Users:JS:Folder:File.gz" set D1 to POSIX path of file "Macintosh HD:Users:JS:Desktop:Untitled CD.fpbf" do shell script "cp -p " & S1 & D1 on running this it says Untitled is not a file! or if I put a colon after the .fpbf in the setting of the variable it says Directory CD.fpbf does not exist. This doesn't seem to make sense - it deals with the space in 'Macintosh HD' but not 'Untitled CD.fpbf' So I read the TN again and tried the 'quoted path' as in : set S1 to quoted form of the POSIX path of file "Macintosh HD:Users:JS:Folder:File.gz" The result is a dialog saying: Can't get the file "Macintosh HD:Users:JS:Folder:File.gz" Interstingly, if I don't bother with the variable and do: do shell script "cp -p " & quoted form of the POSIX path of "Macintosh HD:Users:JS:Folder:File.gz" & quoted form of the POSIX path of "Macintosh HD:Users:JS:Desktop:Untitled CD.fpbf" I get an error 'Can't make quoted form of POSIX path of "Macintosh HD:Users:JS:Folder:File.gz" of <<script>> into type Unicode text. That seems contradictory to the TN? duh - that is the correct path! I'm going round in circles. Can you give any more specific help or pointers? Last edited by jspitzel; 04-21-2008 at 08:50 AM. |
|
|
|
|
|
#11 |
|
Prospect
Join Date: Apr 2008
Posts: 10
|
finally!
I've been working at this for hours - but finally it works!!
solution (with help from http://bbs.macscripter.net/viewtopic.php?pid=85208 ) It's quite easy but only if you know the archane syntax rules Use this to copy a file with a space in the filename using applescript set Sourcefile to POSIX path of "Macintosh HD:Users:JS:Folder:opera.gz" set Destination to POSIX path of "Macintosh HD:Users:JS:Desktop:Untitled CD.fpbf:" do shell script "cp -p " & quoted form of Sourcefile & " " & quoted form of Destination what a bloody palaver Thanks to all |
|
|
|
|
|
#12 |
|
Major Leaguer
Join Date: Feb 2007
Posts: 411
|
use single quotes or escape double qoutes
do shell script "cp -p "&"/Users/JS/Documents/thefile.gz"&" "&"/Users/JS/Desktop/'Untitled CD.fpbf'/thefile.gz" or do shell script "cp -p "&"/Users/JS/Documents/thefile.gz"&" "&"/Users/JS/Desktop/\"Untitled CD.fpbf\"/thefile.gz"
__________________
Please respond, I am desperate for human contact! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|