Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Improving a Script

Improving a Script
Thread Tools
selowitch
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jan 4, 2005, 10:10 PM
 
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. )
     
suthercd
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
Jan 7, 2005, 11:33 AM
 
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:33 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,