|
|
Improving a Script
|
|
|
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
I'm trying to make a script that deletes my cache and histories for Firefox all at once. Here's where I am now:
Code:
--- first, set the necessary variables
set drivename to "Maxtor HD"
set username to "sam_elowitch"
set realname to "Sam Elowitch"
set default to "hjk3wx63.Default User"
set user to "640yf9lw.slt"
--- second, ensure that Firefox is not open
tell application "Firefox"
try
quit application
end try
end tell
--- third, locate and delete the relevant cache and history files
--- need to pause long enough here to ensure that Firefox has truly quit or the deletions will not occur and an error message will appear
set the_path to drivename & ":Users:" & username & ":Library:Mozilla:Profiles:" & realname & ":" & user & ":Cache:"
tell application "Finder"
try
if folder the_path is not (empty) then move every file in folder the_path to the trash
end try
try
set the_path to drivename & ":Users:" & username & ":Library:Application Support:Firefox:Profiles:" & default
if exists file "formhistory.dat" in folder the_path then move file "formhistory.dat" in folder the_path to the trash
if exists file "history.dat" in folder the_path then move file "history.dat" in folder the_path to the trash
end try
try
empty the trash
end try
end tell
I'm not sure how to check for Firefox being fully inactive, nor am I sure how to the idle handler to create a delay. Also, it seems like I should be able to replace the drivename/Users/username string with "~", but if I do so, my script no longer works -- why?
(
Last edited by selowitch; Jan 4, 2005 at 10:16 PM.
)
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Couple of suggestions. Look at the path to command in the Standard Addtions scripting addition dictionary. This returns either an alias or string of several default folders.
Code:
set cache_path to (path to library folder of user domain as string) & "Mozilla:Profiles:" & realname & ":" & user & ":Cache:"
set support_path to (path to application support of user domain as string) & "Firefox:Profiles:" & default
There is a delay command in applescript that will pause excution for a specified time. Or you can set up a repeat loop that will call an quit handler until the app preocess is no longer running.
Code:
set appToCheck to "Mail"
set isRunning to true
repeat while isRunnning
tell application "Finder"
set processList to name of processes
if appToCheck is in processList then
QuitApplication(appToCheck)
else
set isRunning to false
end if
end tell
end repeat
on QuitApplication(appToCheck)
tell application appToCheck to quit
end QuitApplication
You may want to use System Events rather than the Finder to check if a file exists. Ot use a try block and set an alias to the file in question, if it fails then the file does not exist.
Craig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|