(* SafariHistoryRanking *) set safariHistoryFile to (((path to library folder from user domain) as string) & "Safari:History.plist") as alias set htmlPath to (((path to desktop from user domain) as string) & "MySafariHistoryRanking.html") property CR : ASCII character 13 tell application "System Events" set theProperties to contents of property list file (safariHistoryFile as Unicode text) set theWebHistory to value of property list item "WebHistoryDates" of theProperties end tell set headerSource to makeHead() set tableSource to makeTable(theWebHistory) set htmlSource to "" & CR & headerSource & "" & CR & tableSource & "" & CR & "" writeFile(htmlPath, htmlSource) beep on makeHead() set str to "" & CR set str to str & "" & CR set str to str & "Safari History Ranking" & CR set str to str & "" & CR set str to str & "" & CR return str end makeHead on makeTable(theList) -- set theList to items 1 thru 1000 of theList set resultList to {} set end of resultList to "" & CR set minCount to 3 set theStep to 200 repeat with i from 1 to ((((length of theList) - 1) div theStep) + 1) set idxHead to (1 + theStep * (i - 1)) set idxTail to (theStep * i) if length of theList < idxTail then set idxTail to length of theList set theSubList to items idxHead thru idxTail of theList set resultSubList to {} repeat with theItem in theSubList set theVisitCount to |visitCount| of theItem as integer if minCount <= theVisitCount then set theURI to || of theItem set theTitle to theURI try set theTitle to title of theItem end try set tableRow to ("" & CR) set end of resultSubList to tableRow end if end repeat set end of resultList to resultSubList end repeat set end of resultList to "
CountTitle
" & theVisitCount & "" & theTitle & "
" & CR return resultList as string end makeTable on writeFile(filePath, theContent) set tempFilePath to (path to temporary items folder as string) & "MySafariHistoryRankingTemp.html" try set filePointer to open for access file tempFilePath with write permission set eof filePointer to 0 write theContent as Unicode text to filePointer close access filePointer on error errorMessage try close access filePointer end try end try do shell script "/usr/bin/iconv -f utf-16 -t utf-8 " & POSIX path of tempFilePath & " > " & POSIX path of filePath do shell script "rm " & POSIX path of tempFilePath tell application "System Events" set creator type of file filePath to "" set file type of file filePath to "" end tell end writeFile