I’m writing an app to unjumble an entered word and put the results in a table view. For some reason nothing happens upon clicking the unjumble button. I’ve double and triple checked that everything is hooked up in IB correctly. Anyone spot anything in the code? I also made sure I added the anagrammatize.txt file to the resources as well.
-- Unjumbler.applescript
-- Unjumbler
property thewords : missing value
property tableList : {}
property counter : 0
on action theObject
if the name of theObject is "entryField" then
start progress indicator "pi" of window "main"
try
set theEntry to contents of text field "entryField" of window "main"
anagrammatize(theEntry, "")
set end of tableList to {thewords}
set counter to count of thewords
tell window "main"
set contents of table view "resultView" of scroll view "scrollView" to tableList
set contents of text field "resultCounter" to counter & " results returned"
end tell
(*on error
display dialog "Sorry, no results were found." attached to window "main"*)
end try
end if
end action
on clicked theObject
if the name of theObject is "unjumbleButton" then
start progress indicator "pi" of window "main"
try
set theEntry to contents of text field "entryField" of window "main"
anagrammatize(theEntry, "")
set end of tableList to {thewords}
set counter to count of thewords
tell window "main"
set contents of table view "resultView" of scroll view "scrollView" to tableList
set contents of text field "resultCounter" to counter & " results returned"
end tell
(*on error
display dialog "Sorry, no results were found." attached to window "main"*)
end try
stop progress indicator "pi" of window "main"
end if
end clicked
on anagrammatize(someText, dictionaryPath)
if length of someText is 1 then return someText
-- This subroutine must be able to find its dictionary
if dictionaryPath is "" then
set dictionaryPath to path to me as Unicode text
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to ":"
try
tell dictionaryPath to ¬
set dictionaryPath to text 1 thru text item (((last character is not ":") as integer) - 3) & ":"
end try
set text item delimiters of AppleScript to prevTIDs
set dictionaryPath to POSIX path of (dictionaryPath & "anagrammatize.txt")
end if
set signature to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
repeat with thisChar in characters of someText
set i to ASCII number thisChar
-- Handle uppercase letters [A-Z] as lowercase
if i ≥ 65 and i ≤ 90 then set i to i + 32
-- Only lowercase letters are handled [a-z]
if i ≥ 97 and i ≤ 122 then
set i to i - 96
set item i of signature to (item i of signature) + 1
end if
end repeat
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to ""
set signature to "" & signature
set text item delimiters of AppleScript to prevTIDs
do shell script "/usr/bin/grep " & quoted form of ("^" & signature) & " " & quoted form of dictionaryPath & " | /usr/bin/cut -f 2 | /usr/bin/grep --invert-match " & quoted form of ("^" & someText & "$")
set thewords to paragraphs of result
set thewords to thewords as list
end anagrammatize