I’m trying to build a small applet which will do the following:
If a user’s FireFox Profile folder is corrupt, we need to backup the bookmarks file. We also want that backup file placed in a separate folder which has the name consists of the date and time the applet was run.
After the backup of the bookmarks file the FireFox user profile folder can be deleted. With the result that the user can start FireFox up again with a clean profile folder.
But is does not work, can someone tell me what I did wrong? And how to solve the possibility of multiple profile folders and choosing the right one, 9 out of 10 times this corrupt folder ends with .default.
Thanks in advance
below the script so far:
set UserFireFoxProfilePath to (path to application support folder from the user domain as string) & "Firefox:Profiles:" as text
set Mydate to do shell script "date +%Y%m%d%H%m%S" as text --Unique number for folder name
tell application "Finder"
set UserFireFoxProfileName to get name of every folder in folder UserFireFoxProfilePath as text
end tell
set PathToUserFireFoxProfile to UserFireFoxProfilePath & UserFireFoxProfilePath
set FromBookMarksPath to PathToUserFireFoxProfile & "bookmarks.html" as text
set BackUpBookMarksPath to (path to documents folder from the user domain as string) & "BackUp_FireFox_BookMarks_" & Mydate as text
tell application "Finder"
if UserFireFoxProfilePath exists then
make new folder at (path to documents folder from the user domain as string) with properties {name:"BackUp_FireFox_BookMarks_" & Mydate}
duplicate file FromBookMarksPath to BackUpBookMarksPath
if file (path to documents folder from the user domain as string) & "BackUp_FireFox_BookMarks_" & Mydate & "bookmarks.html" exists then
display dialog
"Done! backup placed in your documents folder with the name " & "BackUp_FireFox_BookMarks_" & Mydate
end if
end if
end tell
Here is a working version of what you had so far. The problem was one of the variables you were setting up was done so incorrectly and you forgot a “:” in defining one of your paths.
set UserFireFoxProfilePath to (path to application support folder from the user domain as string) & "Firefox:Profiles:" as text
set Mydate to do shell script "date +%Y%m%d%H%m%S" as text --Unique number for folder name
tell application "Finder"
set UserFireFoxProfileName to get name of every folder in folder UserFireFoxProfilePath as text
end tell
set PathToUserFireFoxProfile to UserFireFoxProfilePath & UserFireFoxProfileName
set FromBookMarksPath to PathToUserFireFoxProfile & ":bookmarks.html" as text
set BackUpBookMarksPath to (path to documents folder from the user domain as string) & "BackUp_FireFox_BookMarks_" & Mydate as text
tell application "Finder"
if UserFireFoxProfilePath exists then
set BackUpBookMarksPathFolder to make new folder at (path to documents folder from the user domain as string) with properties {name:"BackUp_FireFox_BookMarks_" & Mydate}
duplicate file FromBookMarksPath to BackUpBookMarksPath
if file ((BackUpBookMarksPathFolder as Unicode text) & "bookmarks.html") exists then
display dialog "Done! backup placed in your documents folder with the name " & "BackUp_FireFox_BookMarks_" & Mydate
end if
end if
end tell
Now as for dealing with multiple profiles there are a few ways you can handle it… Back up all the profiles you find, use whichever one ends in default, or allow the user to select from a list you populate. Either that or there maybe a preference file you can read a value out of to determine which is the active profile, but I’m not sure.
Is this any more successful? (One profile only. I don’t know how multiple profiles are arranged.)
set UserFireFoxProfilePath to (path to application support folder from user domain as Unicode text) & "Firefox:Profiles:"
set Mydate to (do shell script "date +%Y%m%d%H%M%S") --Unique number for folder name
set BackUpFolderName to "BackUp_FireFox_BookMarks_" & Mydate
tell application "Finder"
if (folder UserFireFoxProfilePath exists) then
try
set UserFireFoxBookmarksFile to file "bookmarks.html" of first folder of folder UserFireFoxProfilePath
set BackUpBookmarksFolder to (make new folder at (path to documents folder from user domain) with properties {name:BackUpFolderName})
duplicate UserFireFoxBookmarksFile to BackUpBookmarksFolder
display dialog "Done! Backup placed in your documents folder in the folder " & BackUpFolderName
on error msg number errN
if (errN is not -128) then display dialog msg
end try
end if
end tell
9 out 10 times this will work, will keep thinking if there is a way to implement that kind of solution.
As promised the solution as is.
No Warranties of course…
global BackUpBookmarksFolder
global CreationDate
global UserFireFoxProfilePath
global CorruptProfileFolder
global UserTrash
global FireFoxFolderPath
-- Script
-- set globals
set UserFireFoxProfilePath to (path to application support folder from user domain as Unicode text) & "Firefox:Profiles:"
set CreationDate to (do shell script "date +%Y%M%d%H%M%S") --Unique number for folder name
set BackUpFolderName to "BackUp_FireFox_BookMarks_" & CreationDate
set CorruptProfileFolder to (path to application support folder from user domain as Unicode text) & "Firefox:Profiles"
set FireFoxFolderPath to (path to application support folder from user domain as Unicode text) & "Firefox:"
set UserTrash to (path to trash folder from user domain as Unicode text)
-- end set globals
-- Make Backup
tell application "Finder"
if (folder UserFireFoxProfilePath exists) then
try
set UserFireFoxBookmarksFile to file "bookmarks.html" of first folder of folder UserFireFoxProfilePath
set BackUpBookmarksFolder to (make new folder at (path to documents folder from user domain) with properties {name:BackUpFolderName})
duplicate UserFireFoxBookmarksFile to BackUpBookmarksFolder
display dialog "Done! Backup placed in your documents folder in the folder " & BackUpFolderName
on error msg number errN
if (errN is not -128) then display dialog msg
end try
end if
end tell
-- end Make Backup
-- Start Delete
tell application "Finder"
if (BackUpBookmarksFolder exists) then
try
set PathToIniFile to (path to application support folder from user domain as Unicode text) & "Firefox:profiles.ini"
set DeleteIniFile to delete PathToIniFile
set DeleteFolder to delete CorruptProfileFolder --to UserTrash
set FolderCreate to (make new folder at FireFoxFolderPath with properties {name:"Profiles"})
display dialog "Done! Corrupt Profile placed in your trash."
on error msg number errN
if (errN is not -128) then display dialog msg
end try
end if
end tell
-- End Delete]
I haven’t had an opportunity yet to try it on my Tiger machine, but on my Jaguar machine, my duplication code doesn’t work if Firefox has quit recently. Presumably, it’s because Firefox renames the current bookmark file when it quits and moves it to the “bookmarkbackups” folder before creating a new “bookmarks.html” file in the original folder. The Finder has no knowledge of the new file and so can’t duplicate it. I’ve found that telling it to update the file a couple of times beforehand will it force it to do the necessary research.
Also, the on error section of my try block stops the “User canceled.” error from being displayed, but doesn’t then allow it to stop the script. Sorry about that. :rolleyes:
Here’s a slight revamp of your full script that takes the above into account. I’ve also commented out a few things that don’t seem to be necessary and have changed the path parameters in the second half to file or folder specifiers. I hope it’s a little more reliable now.
(* global BackUpBookmarksFolder
global CreationDate
global UserFireFoxProfilePath
global CorruptProfileFolder
global UserTrash
global FireFoxFolderPath *)
-- Script
-- set globals
set DocumentsFolder to (path to documents folder from user domain)
set ApplicationSupportPath to (path to application support from user domain as Unicode text)
set UserFireFoxProfilePath to ApplicationSupportPath & "Firefox:Profiles:"
set CreationDate to (do shell script "date +%Y%m%d%H%M%S") --Unique number for folder name
set BackUpFolderName to "BackUp_FireFox_BookMarks_" & CreationDate
set CorruptProfileFolder to ApplicationSupportPath & "Firefox:Profiles"
set FireFoxFolderPath to ApplicationSupportPath & "Firefox:"
-- set UserTrash to (path to trash folder from user domain as Unicode text)
-- end set globals
-- Make Backup
tell application "Finder"
if (folder UserFireFoxProfilePath exists) then
try
set UserFireFoxBookmarksFile to file "bookmarks.html" of first folder of folder UserFireFoxProfilePath
-- Update the Finder's information about the file in case it's recently been replaced.
update UserFireFoxBookmarksFile
update UserFireFoxBookmarksFile -- Once more for luck.
set BackUpBookmarksFolder to (make new folder at DocumentsFolder with properties {name:BackUpFolderName})
duplicate UserFireFoxBookmarksFile to BackUpBookmarksFolder
display dialog "Done! Backup placed in your documents folder in the folder " & BackUpFolderName
on error msg number errN
if (errN is -128) then error number -128 -- Stop the script if the user clicked "Cancel" in the dialog above.
display dialog msg
end try
end if
end tell
-- end Make Backup
-- Start Delete
tell application "Finder"
if (BackUpBookmarksFolder exists) then
try
set PathToIniFile to ApplicationSupportPath & "Firefox:profiles.ini"
-- set DeleteIniFile to
delete file PathToIniFile
-- set DeleteFolder to
delete folder CorruptProfileFolder --to UserTrash
set FolderCreate to (make new folder at folder FireFoxFolderPath with properties {name:"Profiles"})
display dialog "Done! Corrupt Profile placed in your trash."
on error msg number errN
if (errN is -128) then error number -128 -- Probably not necessary if this is the end of the script anyway.
display dialog msg
end try
end if
end tell