I Cannot Believe it, I formatted The Drive, Re-Wrote My Code, Ran it and Wham it works…
As to the question about running it natively - It Worked
What i still don’t get is how i was getting permission denied even when the drive wasn’t plugged in. I ran Disk Utils Drive Perm Fix, and also Ran Onyx Perm Fix Option - Not sure if these helped fix the issue.
Attached Below is my Backup Code Fully Working,
THANKS TO ALL IN THIS THREAD!!! YOUR HELP HAS BEEN GREAT!!!
-- Dialog to Specify Which Command to Run, Backup, Restore or Cancel
display dialog "Choose From The Options Below" buttons {"Backup", "Restore", "Cancel"} default button 3 with title "iDrive Controls V3.0" with icon caution
if the button returned of the result is "Backup" then
tell application "Terminal"
activate
-- sets colour of terminal
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 170
set the number of rows of window 1 to 100
set the position of window 1 to {0, 20}
-- does scripts on after each other once complete
-- R - Makes sure Copies Folder V - Shows What is Being Coppied
-- iDrive = External USB Drive
do script "cp -Rv $HOME/Library/Thunderbird /Volumes/iDrive" in window 1
do script "cp -Rv $HOME/Library/Safari/Bookmarks.plist /Volumes/iDrive/" in window 1
do script "cp -Rv $HOME/Pictures /Volumes/iDrive/" in window 1
do script "cp -Rv $HOME/Music /Volumes/iDrive/" in window 1
do script "cp -Rv $HOME/Documents /Volumes/iDrive/" in window 1
do script "cp -Rv $HOME/Movies /Volumes/iDrive/" in window 1
do script "cp -Rv $HOME/Downloads /Volumes/iDrive/" in window 1
end tell
else
if the button returned of the result is "Restore" then
tell application "Terminal"
activate
-- sets colour of terminal
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 170
set the number of rows of window 1 to 100
set the position of window 1 to {0, 20}
-- does scripts on after each other once complete
-- R - Makes sure Copies Folder V - Shows What is Being Coppied
-- T Drive = External USB Drive
do script "cp -Rv /Volumes/iDrive/Downloads /$HOME/" in window 1
do script "cp -Rv /Volumes/iDrive/Pictures /$HOME/" in window 1
do script "cp -Rv /Volumes/iDrive/Music /$HOME/" in window 1
do script "cp -Rv /Volumes/iDrive/Documents /$HOME/" in window 1
do script "cp -Rv /Volumes/iDrive/DMovies /$HOME/" in window 1
do script "cp -Rv /Volumes/iDrive/Thunderbird /$HOME/Library" in window 1
do script "cp -Rv /Volumes/iDrive/Bookmarks.plist /$HOME/Library/Safari/" in window 1
end tell
else
if the button returned of the result is "Cancel" then
end if
end if
end if
I’ve been trying to work on some refinements to the above
1 - Get terminal to export what has run into a text file onto the desktop after it has run
Using This - Can’t Get it to work though:
tell application "Terminal"
tell window 1
save in "/$Home/Desktop/Jay.ttx"
end tell
end tell
*** Issue 1 Half Resolved ****
set myLog1 to "/$HOME/Desktop/Archive_Log.log"
set theDate to (current date) as text
do shell script "echo " & return & "Start Archiving sequence at " & theDate & ">>" & myLog1
do shell script "cp -Rv $HOME/Data3 /Volumes/iDrive/" & ">>" & myLog1
tell application “Terminal”
activate
set myLog1 to “/$HOME/Desktop/Archive_Log.log”
set theDate to (current date) as text
do shell script "echo " & return & "Start Archiving sequence at " & theDate & “>>” & myLog1
do script “cp -Rv $HOME/Data3 /Volumes/iDrive/” & “>>” & myLog1
end tell
This is great, but when i use it via terminal it does not do the verbose mode i want, it adds info to log, bu doesn't show progress. Any ideas on how i can get terminal to save output into a file after it has finished all the CP requests?
2 - Get Terminal to close when all the do scripts have finished.
To be honest i have not had much luck with any of it, can anyone help please?
If you launch the copy commands with do shell script and redirect their output somewhere you can have Terminaldo script "touch “"ed form of myLog1&” && tail -f ""ed form of myLog1 to monitor the accumulated output.
Or, you can launch the copy commands with Terminal and use the tee command to also save the output. The tee command saves a copy of its input to a file while also copying it to its output.
Saving the history of a Terminal window seems like it could be problematic since the scroll back (history) buffer may not be unlimited (though that is an option in my version of Terminal).
There are also a couple of ways to close the window.
If you are running the copy commands with do shell script (and tailing the log file in Terminal), your program will know when they are finished because they are executed synchronously (the do shell script command does not return until (and the next AppleScript statement does not execute until) its command has finished. It could tell Terminal to close the window after the last copy command finishes.
set myLog1 to do shell script "echo \"$HOME/Desktop/Archive_Log.log\"" -- expand "$HOME" so we can use 'quoted form of' later
tell application "Terminal"
do script "touch " & quoted form of myLog1 & " && tail -f " & quoted form of myLog1
set logWindow to window 1
end tell
do shell script "cp -Rv \"$HOME\"/Data1 /Volumes/iDrive/ >> " & quoted form of myLog1
do shell script "cp -Rv \"$HOME\"/Data2 /Volumes/iDrive/ >> " & quoted form of myLog1
do shell script "cp -Rv \"$HOME\"/Data3 /Volumes/iDrive/ >> " & quoted form of myLog1
tell application "Terminal" to close logWindow
Unfortunately, this may cause Terminal to display an confirmation sheet that says something like “Some processes are still running, are you sure you want to terminate them and close the window?”.
If you are running the commands in Terminal (and possibly using tee to save a copy of the output), you could add an exit command to the end. Terminal has options for what to do when the shell exits: close the window, close the window if the shell exited with a zero exit code, leave the window open. You would have to configure Terminal to do one of the first two.
set myLog1 to do shell script "echo \"$HOME/Desktop/Archive_Log.log\"" -- expand "$HOME" so we can use 'quoted form of' later
tell application "Terminal"
activate
do script ¬
"{
echo 'Start Archiving sequence at '\"$(date)\"
cp -Rv \"$HOME\"/Data1 /Volumes/iDrive/
cp -Rv \"$HOME\"/Data2 /Volumes/iDrive/
cp -Rv \"$HOME\"/Data3 /Volumes/iDrive/
} 2>&1 | tee -a " & quoted form of myLog1 & "
exit 0"
end tell
Many thanks for the coded examples above. I have tried both given examples, and although they both work, they both still stop the verbose element -v in the CP function.
I really like to use the verbose function to see exactly what the system is copying as it goes.
is there anyway to save the terminal contents once it has finished directly.
For example, on terminal you can export to file under the Shell Option
any further help would be much appreciated, and again i do appreciate all the help you have provided above.
Why do you want to mointor the progress using the terminal?
Just activate Console and write the output to a .log file
I use this frequently to test and monitor my shell commands like mv, cp or rsync
set source_dir to "/your/source/"
set dest_dir to "/your/dest/"
set myLog1 to "$HOME/Desktop/Archive_Log.log"
set myLog2 to (path to desktop as text) & "Archive_Log.log"
set theDate to (current date) as text
do shell script "echo " & return & "Start Archiving sequence at " & theDate & ">>" & myLog1
tell application "Console" to activate
tell application "System Events" to keystroke "w" using command down --close the frontmost console window
do shell script "/bin/sleep 2" --give it some time...
tell application "Console" to open myLog2
do shell script "find " & source_dir & " -type f | wc -l" -- get number of files
set totalfiles to the result
do shell script "echo " & return & "number of files to be copied: " & quoted form of totalfiles & return & return & ">>" & myLog1
do shell script "/bin/sleep 2" --give some time to see the number of files...
do shell script "cp -Rv " & source_dir & space & dest_dir & ">>" & myLog1
do shell script "echo " & return & "Finished Archiving sequence at " & theDate & ">>" & myLog1
I get the verbose output when I run my second script (all commands in one do script) with modified paths that work on my system.
As I wrote before, “Saving the history of a Terminal window seems like it could be problematic since the scroll back (history) buffer may not be unlimited (though that is an option in my version of Terminal).”
If you are willing to live with the possibility of losing the first part of the log then you might be able to get the data with something like history of window 1 in a Terminaltell block.
That does not appear to be in my version of Terminal (from 10.4).