Guest User

Untitled

a guest
Jun 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. set theWord to text returned of (display dialog "What word do you need to synonymizifucate?" default answer "")
  2. set theType to text returned of (display dialog "What kind of word is it? (e.g. adjective, verb, noun, etc.)" default answer "")
  3. activate application "Dictionary"
  4. tell application "System Events" to tell process "Dictionary"
  5. key code 19 using {command down}
  6. keystroke contents of theWord & return
  7. end tell
  8. set synonyms to text returned of (display dialog "Paste in the synonyms you would like to include (each separated by a comma)" default answer "")
  9. set ASTID to AppleScript's text item delimiters
  10. set AppleScript's text item delimiters to {", "}
  11. set synonyms_list to text items of synonyms
  12. set AppleScript's text item delimiters to ASTID
  13. set theStuff to ""
  14. repeat with synonym in synonyms_list
  15. set pyscriptpath to quoted form of (POSIX path of (((path to me) as Unicode text) & ":autoSynonym.scptd:Contents:Resources:dict.py"))
  16. set command to "/usr/bin/python " & pyscriptpath & " " & quoted form of synonym
  17. set dictresult to (do shell script command)
  18. set AppleScript's text item delimiters to (return as text)
  19. set dictitems to text items of dictresult
  20. set AppleScript's text item delimiters to ASTID
  21. set i to 1
  22. try
  23. repeat
  24. if (item i of dictitems as string) contains theType then
  25. set definition to item (i + 1) of dictitems
  26. exit repeat
  27. end if
  28. set i to (i + 1)
  29. end repeat
  30. end try
  31. try
  32. set firstLetter to character 1 of synonym
  33. considering case
  34. if firstLetter is not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" then set firstLetter to makeUPPER(firstLetter)
  35. if length of synonym > 1 then
  36. set lowerletters to text 2 thru (length of synonym) of synonym
  37. set lowerletters to makelower(lowerletters)
  38. else
  39. set lowerletters to ""
  40. end if
  41. set newName to firstLetter & lowerletters
  42. set AppleScript's text item delimiters to {space}
  43. set synonym to newName as text
  44. set AppleScript's text item delimiters to {}
  45. set theStuff to theStuff & synonym & ": " & definition & (return as text)
  46. end considering
  47. end try
  48. end repeat
  49. tell application "TextEdit"
  50. activate
  51. set text of (make new document) to theStuff
  52. end tell
  53.  
  54. on makeUPPER(aLetter)
  55. --see if the letter is in list of lower case letters
  56. considering case
  57. set myChar to offset of aLetter in "abcdefghijklmnopqrstuvwxyz"
  58. --if so, then return the upper case version
  59. if myChar > 0 then
  60. return character myChar of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  61. else
  62. --else return the original character (it might be a number!)
  63. return aLetter
  64. end if
  65. end considering
  66. end makeUPPER
  67.  
  68. on makelower(theText)
  69. set newText to ""
  70. --loop through the letters
  71. repeat with loop from 1 to (length of theText)
  72. --convert them to lower case
  73. set newText to newText & lower(character loop of theText)
  74. end repeat
  75. --return the new text
  76. return newText
  77. end makelower
  78.  
  79. on lower(aLetter)
  80. --see if the letter is in list of upper case letters
  81. considering case
  82. set myChar to offset of aLetter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  83. --if so, then return the lower case version
  84. if myChar > 0 then
  85. return character myChar of "abcdefghijklmnopqrstuvwxyz"
  86. else
  87. --else return the original character (it might be a number!)
  88. return aLetter
  89. end if
  90. end considering
  91. end lower
Add Comment
Please, Sign In to add comment