I am a learning novice, so please be patient with me. I do not know terminal/unix commands, etc. despite using macs for 18 yrs.
Objective: download a text-like file from a web page, replace the older equivalent file in a userās program preference folder.
Steps:
1. Download file.
2. Replace the older file. Ideally (1) & (2) would happen simultaneously but Iāve not been able to achieve this. (eg: download & replace.)
3. Chronologically, this would occur first: Check to be sure the older file is not busy.
I suspect an experienced scripter would take about 3 minutes to write the above script.
I seem to be having problem getting the file to move & replace the older file. Not sure the script can even find the folder. Iāve tried almost 20 ways of achieving this. Presently the download command simply downloads the file to the root of the startup drive (/).
This part works alone but downloads to root:
try
display dialog ("LimeWire must be closed before running this Fix program")
set newFile to ("gnutella.net")
tell application "URL Access Scripting"
activate
download "http://dl.frostwire.com/frostwire/gnutella.net" to newFile with progress
display dialog ("Fix finished. ...")
quit
end tell
end try
Original attempts to download directly to the location failed:
try
display dialog ("LimeWire must be closed before running this Fix program")
set newFile to ("gnutella.net")
set theDestinationPath to "~/preferences/LimeWire/"
tell application "URL Access Scripting"
activate
download "http://dl.frostwire.com/frostwire/gnutella.net" to "~/Preferences/LimeWire/gnutella.net" with progress and replacing
display dialog ("Finished, now ...")
quit
end tell
end try
Attempts to move the file have failed. Below is simply an example of my last attempt:
try
display dialog ("LimeWire must be closed before running this Fix program")
set newFile to ("gnutella.net")
tell application "URL Access Scripting"
activate
download "http://dl.frostwire.com/frostwire/gnutella.net" to newFile with progress
set theSourcePath to newFile
set theDestinationPath to "~/preferences/limewire/"
tell application "Finder"
move newFile to theDestinationPath with replacing
display dialog ("Finished, now ..")
quit
end tell
end tell
end try
This script combining downloading & checking if file to be replaced is busy does not appear to work at all, I guess the isBusy part is incorrect:
to isBusy(f)
set f to f as Unicode text
display dialog ("LimeWire must be closed before running this Fix program")
if f does not contain ":" then set f to POSIX file f as Unicode text
try
open for access file (system attribute "HOME") & ("~preferences/LimeWire/gnutella.net") with write permission
close access result
return false
if false then
set newFile to ("gnutella.net")
tell application "URL Access Scripting"
activate
download "http://dl.frostwire.com/frostwire/gnutella.net" to newFile with progress
display dialog ("Fix finished.
Now open LimeWire and see if it connects.
Wait 3-4 minutes for it to connect.
If no connection, CLOSE LimeWire.
Wait another 2 minutes, then run this script again.")
end tell
else
return true
display dialog ("LimeWire settings are still active, close this fix program and wait a minute before trying again")
end if
on error
display dialog ("LimeWire settings are still active or you do not have an active internet connection, close this fix program and wait a minute before trying again")
quit
end try
end isBusy
Side questions: From my understanding, if this script were offered as a program, it would only be compatible with OSX 10.5 & above?
If I wished to recreate equivalent for OSX 10.4 down to OS9, would this be possible & which version of Applescript? I still have G4 with OSX 10.4 & 10.3 (with Classic.)
I am more used to using VISE which is very easy for itās basic functions, but unfortunately does not support actively updating installers such as this project (I had wondered if one could be combined with applescript.)
Model: 2x3.2 Quad Core, OSX 10.6.8
AppleScript: AppleScript 2.1.2, A.Editor 2.3
Operating System: Mac OS X (10.6)
Edit: Removed some unnecessary script dialog to save space in post.