I have a backup script that copies my main home folders to an external drive. At present the script runs, but i have no idea what % it has done, or what area it is currently copying.
Script:
do shell script "cp -R $HOME/Data1 /Volumes/CAPSULE/"
do shell script "cp -R $HOME/Data2 /Volumes/CAPSULE/"
do shell script "cp -R $HOME/Data3 /Volumes/CAPSULE/"
Is there anyway to have a dialog box that stays up and stated what are the code is copying e.g:
If you want to do it with applescript and display dialog-commands? Take a look at this:
set folderToCopy to (choose folder with prompt "Please choose a folder to copy:") as string
set copyDirectory to (choose folder with prompt "Please choose backup directory:") as string
set copyDirectory to (POSIX path of copyDirectory)
set copyDirectory to ConvertName(copyDirectory)
tell application "Finder" to set allFilesToCopy to every item of alias folderToCopy
repeat with i from 1 to (count allFilesToCopy)
set theFileToCopy to (item i of allFilesToCopy) as alias
set thePOSIXPath to (POSIX path of theFileToCopy) as string
display dialog ("I will now copy file " & (i as string) & "/" & ((count allFilesToCopy) as string) & ":" & return & return & thePOSIXPath) as string
set terminalPath to ConvertName(thePOSIXPath)
do shell script ("cp -R " & terminalPath & " " & copyDirectory) as string
end repeat
display dialog "All went right! Goodbye!" buttons "OK" default button 1
(* ===== HANDLERS ===== *)
on ConvertName(PosixPathString)
set NewName to {}
repeat with i in PosixPathString
if (i as string) is " " then set end of NewName to "\\ "
if (i as string) is not " " then set end of NewName to (i as string)
end repeat
set NewName to NewName as string
return NewName
end ConvertName
Well you if you want to be able to change the paths you could use the user defaults.
Tutorial: http://macscripter.net/viewtopic.php?id=24666
(look at the Gentlemen Prefer Preferences part)
Then you could change the preferences by adding a new menu item to your app’s menu bar, connect it to an applescript and it should be something like this:
on clicked menu item theObject()
if name of theObect is NAMEOFMENUITEM then
set newFolderToCopy to (choose folder with prompt "Please choose the folder to copy:") as alias
set newCopyDestination to (choose folder with prompt "Please choose the backup folder:") as alias
set newFolderToCopy to ConvertName((POSIX path of newFolderToCopy) as string)
set newCopyDestination to ConvertName((POSIX path of newCopyDestination) as string)
-- DON'T FORGET TO ADD THE RIGHT HANDLERS TO THE END OF THE SCRIPT (see earlier posts)
tell user defaults to set contents of default entry "FOLDERTOCOPY" to newFolderToCopy
tell user defaults to set contents of default entry "COPYDESTINATION" to newCopyDestination
end if
end clicked
You could always split it in two menu items.
If you are not willing to change the paths later, you could use a static string in your application.
is there any way i can get the code to launch in terminal and it display what it is doing e.g verbose
do shell script "cp -R $HOME/Data1 /Volumes/CAPSULE/"
do shell script "cp -R $HOME/Data2 /Volumes/CAPSULE/"
do shell script "cp -R $HOME/Data3 /Volumes/CAPSULE/"
This way i can see what files are being coppied and will be able to see progress
Also, has anyone got any ideas how when you launch terminal via applescript, to get it to launch as Homebrew rather than the standard white & black?
Cheers
Update: Fixed the colour issue :
tell application "Terminal"
activate
set the background color of window 1 to "black"
set the normal text color of window 1 to "green"
set the number of columns of window 1 to 50
set the number of rows of window 1 to 15
set the position of window 1 to {0, 20}
end tell
Note you must use lower case in colour name, if you use Caps it Fails
Key:
-R Copy the folder and subtree (recursive).
If source_file designates a directory, cp copies the directory and
the entire subtree connected at that point. If the source_file
ends in a /, the contents of the directory are copied rather than
the directory itself. This option also causes symbolic links to be
copied, rather than indirected through, and for cp to create special
files rather than copying them as normal files. Created
directories have the same mode as the corresponding source directory,
unmodified by the process’ umask.
-H Symbolic links on the command line are followed.
(but Symbolic links encountered in the tree traversal are not followed.)
-L All symbolic links are followed.
-P No symbolic links are followed. This is the default.
-f For each existing destination pathname, remove it and create a new
file, without prompting for confirmation regardless of its permissions.
(The -f option overrides any previous -i or -n options.)
-i Cause cp to write a prompt to the standard error output before
copying a file that would overwrite an existing file. If the
response from the standard input begins with the character y' or Y’, the file copy is attempted. (The -i option overrides any
previous -f or -n options.)
-n Do not overwrite an existing file. (The -n option overrides any
previous -f or -i options.)
-p Cause cp to preserve the following attributes of each source file
in the copy: modification time, access time, file flags, file mode,
user ID, and group ID, as allowed by permissions. Access Control
Lists (ACLs) will also be preserved.
If the user ID and group ID cannot be preserved, no error message
is displayed and the exit value is not altered.
-v Verbose - show files as they are copied.
-X Do not copy Extended Attributes (EAs) or resource forks.
set myLog1 to "/Users/you/Desktop/Archive_Log.log"
set myLog2 to (path to desktop as text) & "Archive_Log.log"
set theDate to (current date) as text
tell application "Console" to activate
tell application "Console" to open myLog2
do shell script "echo " & return & "Start Archiving sequence at " & theDate & ">>" & myLog1
do shell script "cp -Rv $HOME/Data3 /Volumes/CAPSULE/" & ">>" & myLog1
When i run this this is what i get back as a result:
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B1.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B2.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B4.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B6.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B7.JPG: No such file or directory
That is an odd error. It is showing a destination path and saying that it does not exist, but that is usually the point since it is making a copy. I suspect it is something to do with “CAPSULE”, but you should be able to reduce the problem until you have identified it.
Do you get other output (e.g. lines that indicate other files are being copied correctly)? Are any of the other directories (Downloads, Music, Documents, Movies) reporting errors like this? Are any of the other directories being copied at all?
What is the CAPSULE volume? (internal, external, local, remote, LAN, WAN)
How it it being accessed? (SATA, USB, FireWire, eSATA; AFP, SMB, NFS, iSCSI)
Is it, as its name suggests, a network-mounted Time Capsule?
First step, simply the command to just the failing part. If it now succeeds, then the problem may have been triggered by one of the preceding events. If it still fails, then continue simplifying.
tell app "Terminal"
do script "cp -Rv $HOME/Pictures /Volumes/CAPSULE/"
end
If this works, then it would seem to indicate that something about the earlier copies is causing the problem. Maybe the destination is unable to keep up with the many requests that cp is generating (bad disk/device?).
Next, try copying into a fresh directory on CAPSULE.
tell app "Terminal"
do script "mkdir /Volumes/CAPSULE/copy-test && cp -Rv $HOME/Pictures /Volumes/CAPSULE/copy-test"
end
Note, the directory will only be “fresh” the first time you run this. You will have to delete the copy-test directory to repeat the test with a truly fresh directory.
If this works, then it could be something inside /Volumes/CAPSULE/Pictures that is broken (a filesystem corruption?). If it is a local disk, I would ask DIsk Utility to Verify and/or Repair the disk to see if it finds any problems.
Next, try eliminating the volume by copying to a destination on the boot volume.
tell app "Terminal"
do script "mkdir /tmp/copy-test && cp -Rv $HOME/Pictures /tmp/copy-test"
end
Note: Same deal with “freshness” here as above.
If this works (and all the rest still failed), then it strongly indicates that the problem is specific to the /Volumes/CAPSULE disk.
If it is still failing in the same way, then it could be a bug in how cp does its work, or it could be a problem with the source files or directories (though, in that case, the misleading error message from cp could still be called a minor bug). Are the files in the Pictures directory accessible and usable? (Can you open them in Preview?)
its funny you say this, i just ran my old script that does
do shell script “cp -R $HOME/Downloads /Volumes/CAPSULE/”
I get permission is denied / cannot find target
error “cp: /Volumes/CAPSULE/Downloads: Permission denied
cp: /Users/JBird/Downloads: unable to copy extended attributes to /Volumes/CAPSULE/Downloads: Permission denied
cp: /Volumes/CAPSULE/Downloads/.DS_Store: No such file or directory” number 1
This is EXTREMELY strange as all that used to happen when the external HDD “Capsule” wasn’t attached all it did was error and say Edit Script
Have i screwed up my permissions on my folders some how? is there a way to reset folders and items to defaults?
My cp does not contain any strings like “cannot find target”, but then I am still running 10.4.
I have never seen error messages quite like those, but they still lead me to think that something is wrong (misconfigured, corrupt, otherwise broken) on the CAPSULE device (either at the filesystem level, or maybe the hardware itself).
Did copying to a directory on your boot drive work? If so, it strongly indicates that, in my opinion, the problem is with CAPSULE, not with the script or cp.