set the bookmarks_folderpath to the POSIX path of (path to "cach" from user domain) & "Metadata/Safari/Bookmarks/"
tell application "System Events"
set these_bookmark_filepaths to the POSIX path of every disk item of folder bookmarks_folderpath whose name extension is "webbookmark"
-- generate book mark AppleScript list: {{bookmark 1 name, bookmark 1 URL}, {bookmark 1 name, bookmark 1 URL}, etc.}
set the bookmarks_list to {}
repeat with i from 1 to the count of these_bookmark_filepaths
set this_bookmark_path to item i of these_bookmark_filepaths
tell property list file this_bookmark_path
set the end of the bookmarks_list to {value of property list item "Name", value of property list item "URL"}
end tell
end repeat
end tell
-- convert AppleScript list to text
repeat with i from 1 to the count of the bookmarks_list
set this_bookmark to item i of the bookmarks_list
if i is 1 then
set the bookmark_text to (item 1 of this_bookmark) & tab & (item 2 of this_bookmark)
else
set the bookmark_text to the bookmark_text & return & (item 1 of this_bookmark) & tab & (item 2 of this_bookmark)
end if
end repeat
-- write to file
set the target_file to (path to documents folder as string) & "Safari Bookmarks.cvs"
write_to_file(bookmark_text, target_file, false)
-- open in Numbers
tell application "Numbers"
activate
open file target_file
end tell
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file