Hi every body and merry christmas
I’ve made a script to export all the bookmarks in camino. It pictures the Folder structure in camino to finder and saves a bookmark as webloc.
After a few tests I think I it’s pretty good at to moment, although there’s one problem: I can only run it properly when I open it directly in Script Editor. So I can’t run it as an app or run it through Quicksilver, because then it just creates the two Folders “Bookmark Bar” and “Bookmark Menu” in the Folder “Camino Bookmarks” and does NOT save any weblocs.
Maybe you can have a look at this and correct the problem…would be great! Any corrections about other issues are highly appreciated!
thanks
simon
Here’s the Script:
property theLocation : path to desktop
if theLocation is not (path to desktop) then
set theLocation to path to desktop
end if
tell application "Finder"
set theMode to choose from list {"Bookmark Bar only", "Bookmark Menu only", "both"} ¬
with title "Camino Bookmark Export" with prompt "This Script will create the Folder \"Camino Bookmarks\" on your Desktop to store the Bookmarks." & return & return & "Choose export mode:" without empty selection allowed
try
set root_fold to my NewFolderAndReset_theLocation(theLocation, "Camino Bookmarks")
on error
display dialog "Error: Folder \"Camino Bookmarks\" already exists!" buttons {"Cancel", "Trash'n'retry"} default button 2
if the button returned of the result is "Trash'n'retry" then
tell application "Finder" to move ((theLocation as text) & "Camino Bookmarks:") to trash
end if
set root_fold to my NewFolderAndReset_theLocation(theLocation, "Camino Bookmarks")
end try
end tell
tell application "Camino"
if theMode is {"Bookmark Bar only"} then
my NewFolderAndReset_theLocation(theLocation, "Bookmark Bar")
set export_target to bookmark bar collection
my getWeblocs(export_target)
else if theMode is {"Bookmark Menu only"} then
my NewFolderAndReset_theLocation(theLocation, "Bookmark Menu")
my getWeblocs((bookmark menu collection))
else if theMode is {"both"} then
my NewFolderAndReset_theLocation(theLocation, "Bookmark Bar")
set export_target to bookmark bar collection
my getWeblocs(export_target)
set theLocation to root_fold
my NewFolderAndReset_theLocation(theLocation, "Bookmark Menu")
set export_target to bookmark menu collection
my getWeblocs(export_target)
end if
end tell
tell application "Finder" to display alert "Congrats! Camino Bookmark Export has finished with success."
--subrutines
to NewFolderAndReset_theLocation(loc, Fold_Name)
tell application "Finder"
make new folder at loc with properties {name:Fold_Name}
set theLocation to (alias ((loc as text) & Fold_Name & ":"))
return theLocation
end tell
end NewFolderAndReset_theLocation
to getWeblocs(location) --location: bookmark folder in camino (or at the beginning: bookmark bar collection)
-- get the files in location
tell application "Camino"
tell location
set theFiles to every bookmark item
end tell
end tell
--listen füllen
set bookmarks to {}
set bookmark_folders to {}
repeat with each in theFiles
if name of each does not contain "Menu Spacer" then
if (class of each as string) is ("bookmark folder") then
copy each to end of bookmark_folders
else if (class of each as string) is "bookmark" then
copy each to end of bookmarks
end if
end if
end repeat
-- erstmal alle bookmarks erstellen
repeat with each in bookmarks
tell application "Camino"
set theurl to URL of each
set theName to name of each
set theName to my searchReplace(theName, ":", "-")
tell application "Finder" to set webloc to make new internet location file to theurl at theLocation with properties {name:theName}
end tell
end repeat
-- abbruch bdg
if bookmark_folders is {} then return
-- rekursion
repeat with each in bookmark_folders
set folder_name to (name of each)
set folder_name to my searchReplace(folder_name, ":", "-")
tell application "Finder" to set theLocation to make new folder at theLocation with properties {name:folder_name}
my getWeblocs(each)
set theLocation to my get_parent(theLocation)
end repeat
end getWeblocs
to get_parent(loc)
set loc to (my text_to_list(loc as string, ":"))
set blabla to {}
repeat with counter from 1 to ((count of loc) - 2)
copy (item counter of loc) to end of blabla
end repeat
set blabla to list_to_text(blabla, ":")
set blabla to (blabla & ":")
return blabla as alias
end get_parent
to text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list
to list_to_text(theList, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set txt to theList as text
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (txt)
end list_to_text
to searchReplace(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end searchReplace