Marynel Vázquez – Update
I’ve collected a bunch of data about wikipedia’s common misspellings.. I’m working on the visualization now.
Here is an interesting way of using AppleScript to search phrases with Safari (have in mind this is not fast!):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | -- Access Safari and save page on run argv -- check for input arguments or show help if (count of argv) is less than 2 then return "Not enough arguments were given!" & myHelp() end if -- join arguments from 2nd to last set theWords to item 2 of argv repeat with i from 3 to (number of items of argv) set theWords to theWords & " " & (item i of argv) end repeat -- output file comes from argument 1 set sourceFileName to (item 1 of argv) set sourceFileName to POSIX file sourceFileName as string -- play with Safari my SearchWords(theWords, sourceFileName) end run -- Search a particular word or group of words on SearchWords(queryText, sourceFileName) -- enclose query in quotes set queryText to "\"" & queryText & "\"" tell application "Safari" to activate -- add some random delay delay (random number from 2 to 5) tell application "Safari" -- open new window and move to the search bar make new document tell application "System Events" tell process "Safari" keystroke "l" using {command down} delay 1 keystroke tab delay 1 keystroke queryText delay 1 keystroke return end tell end tell delay 3 -- wait until page loads set web_page_is_loaded to false set myCounter to 0 set maxCounter to 50 set my_delay to 2 repeat until web_page_is_loaded is true -- change words here depending on home page if name of window 1 contains "Loading" or name of window 1 contains "Untitled" then delay my_delay else set web_page_is_loaded to true end if set myCounter to myCounter + 1 if myCounter is maxCounter then set web_page_is_loaded to true end if end repeat delay 1 if name of window 1 contains "Loading" or name of window 1 contains "Untitled" or name of window 1 contains "http://www." then -- do nothing! results didn't load... else -- save results page save document 1 in file sourceFileName end if end tell -- close window tell application "System Events" tell process "Safari" keystroke "w" using {command down} delay 1 end tell end tell end QueryWords -- Command usage on myHelp() return " You should pass the output file path and a list of words (at least one) through the command line. this-applescript output-file word1 [word2] [word3] [...]" end myHelp |
The previous script can be called as follows:
1 | arch -i386 osascript this-applescript-path output-path word1 [word2] ... |
Relative paths gave me you-don’t-have-permission-kind-of-errors, so I recommend using full paths. I’m no expert here.. just thought it might be fun to use AppleScript ;)
Hrmm, the next step is pure bash scripting :P