Advertisement
selfire_

Bible Import 2.0

Jul 13th, 2020
1,423
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (* What to do before starting this script:
  2. * Open Safari
  3. * Open Atom in fullscreen, make sure it's empty
  4. * Disable Regrex in Atom *)
  5.  
  6. -- OPTIONS
  7. set shutdown to false -- Do you want your Mac to shut down after importing?
  8. set savedialog to true -- Choose if you want to display a dialog asking you to save each chapter. For longer books I found that helpful to be able to exit out. It has a timeout of 5 seconds if you don't bother picking an option.
  9. set bigdialog to false -- Choose to abort after each imported book
  10. set dialogchosen to false -- Choose if you want a display showing you the books you're about to import
  11.  
  12. set translation to "ESV" -- pick your translation
  13.  
  14. -- BOOKS
  15. -- Pick the books you want to import!
  16. set pickGen to false -- Choose Genesis
  17. set pickExod to false -- Choose Exodus
  18. set pickLev to false -- Choose Leviticus
  19. set pickNum to false -- Choose Numbers
  20. set pickDeut to false -- Choose Deuteronomy
  21. set pickJosh to false -- Choose Joshua
  22. set pickJudg to false -- Choose Judges
  23. set pickRuth to false -- Choose Ruth
  24. set pickoneSam to false -- Choose 1 Samuel
  25. set picktwoSam to false -- Choose 2 Samuel
  26. set pickoneKings to true -- Choose 1 Kings
  27. set picktwoKings to true -- Choose 2 Kings
  28. set pickoneChron to true -- Choose 1 Chronicles
  29. set picktwoChron to true -- Choose 2 Chronicles
  30. set pickEzr to false -- Choose Ezra
  31. set pickNeh to false -- Choose Nehemiah
  32. set pickEsth to false -- Choose Esther
  33. set pickJob to false -- Choose Job
  34. set pickPs to false -- Choose Psalm
  35. set pickProv to false -- Choose Proverbs
  36. set pickEccles to false -- Choose Ecclesiastes
  37. set pickSong to true -- Choose Song of Solomon
  38. set pickIsa to false -- Choose Isaiah
  39. set pickJer to false -- Choose Jeremiah
  40. set pickLam to false -- Choose Lamentations
  41. set pickEzek to false -- Choose Ezekiel
  42. set pickDan to false -- Choose Daniel
  43. set pickHos to false -- Choose Hosea
  44. set pickJoel to false -- Choose Joel
  45. set pickAm to false -- Choose Amos
  46. set pickObad to false -- Choose Obadiah
  47. set pickJonah to false -- Choose Jonah
  48. set pickMicah to false -- Choose Micah
  49. set pickNah to false -- Choose Nahum
  50. set pickHab to false -- Choose Habakkuk
  51. set pickZeph to false -- Choose Zephaniah
  52. set pickHag to false -- Choose Haggai
  53. set pickZech to false -- Choose Zechariah
  54. set pickMal to false -- Choose Malachi
  55. set pickMatt to false -- Choose Matthew
  56. set pickMark to false -- Choose Mark
  57. set pickLuke to false -- Choose Luke
  58. set pickJohn to false -- Choose John
  59. set pickActs to false -- Choose Acts
  60. set pickRom to false -- Choose Romans
  61. set pickoneCor to true -- Choose 1 Corinthians
  62. set picktwoCor to true -- Choose 2 Corinthians
  63. set pickGal to false -- Choose Galatians
  64. set pickEphes to false -- Choose Ephesians
  65. set pickPhil to false -- Choose Philippians
  66. set pickCol to false -- Choose Colossians
  67. set pickoneThess to true -- Choose 1 Thessalonians
  68. set picktwoThess to true -- Choose 2 Thessalonians
  69. set pickoneTim to true -- Choose 1 Timothy
  70. set picktwoTim to true -- Choose 2 Timothy
  71. set pickTitus to true -- Choose Titus
  72. set pickPhilem to true -- Choose Philemon
  73. set pickHeb to true -- Choose Hebrews
  74. set pickJames to true -- Choose James
  75. set pickonePet to true -- Choose 1 Peter
  76. set picktwoPet to true -- Choose 2 Peter
  77. set pickoneJohn to true -- Choose 1 John
  78. set picktwoJohn to true -- Choose 2 John
  79. set pickthreeJohn to true -- Choose 3 John
  80. set pickJude to true -- Choose Jude
  81. set pickRev to true -- Choose Revelation
  82.  
  83. -- VARIABLES
  84. set bookchosen to {}
  85.  
  86. -- DATA
  87. -- # Mouse Coordinates, find those with Shift + Command + 4
  88. -- The text field in Atom
  89. set textX to 53
  90. set textY to 86
  91.  
  92. -- Regrex in atom
  93. set regX to 1121
  94. set regY to 674
  95.  
  96. -- Pick standard folder to save in
  97. set folderX to 290
  98. set folderY to 201
  99.  
  100. -- Choose "New Folder"
  101. set newX to 285
  102. set newY to 470
  103.  
  104. -- DELAYS
  105. -- Set those according to your computing power and internet connection
  106. set DelayStart to 4
  107. set DelayLong to 4
  108. set DelayMed to 0.8
  109. set DelayShort to 0.4
  110.  
  111. -- Book information (Position, name, abbreviation, amount chapters)
  112. set Genlist to {"01", "Genesis", "Gen", 50}
  113. set Exodlist to {"02", "Exodus", "Exod", 40}
  114. set Levlist to {"03", "Leviticus", "Lev", 27}
  115. set Numlist to {"04", "Numbers", "Num", 36}
  116. set Deutlist to {"05", "Deuteronomy", "Deut", 34}
  117. set Joshlist to {"06", "Joshua", "Josh", 24}
  118. set Judglist to {"07", "Judges", "Judg", 21}
  119. set Ruthlist to {"08", "Ruth", "Ruth", 41}
  120. set oneSamlist to {"09", "1%20Samuel", "1 Sam", 31}
  121. set twoSamlist to {"10", "2%20Samuel", "2 Sam", 24}
  122. set oneKingslist to {"11", "1%20Kings", "1 Kings", 22}
  123. set twoKingslist to {"12", "2%20Kings", "2 Kings", 25}
  124. set oneChronlist to {"13", "1%20Chronicles", "1 Chron", 29}
  125. set twoChronlist to {"14", "2%20Chronicles", "2 Chron", 36}
  126. set Ezrlist to {"15", "Ezra", "Ezr", 10}
  127. set Nehlist to {"16", "Nehemiah", "Neh", 13}
  128. set Esthlist to {"17", "Esther", "Esth", 10}
  129. set Joblist to {"18", "Job", "Job", 42}
  130. set Pslist to {"19", "Psalm", "Ps", 150}
  131. set Provlist to {"20", "Proverbs", "Prov", 31}
  132. set Eccleslist to {"21", "Ecclesiastes", "Eccles", 12}
  133. set Songlist to {"22", "Song%20of%20Solomon", "Song", 8}
  134. set Isalist to {"23", "Isaiah", "Isa", 66}
  135. set Jerlist to {"24", "Jeremiah", "Jer", 52}
  136. set Lamlist to {"25", "Lamentations", "Lam", 5}
  137. set Ezeklist to {"26", "Ezekiel", "Ezek", 48}
  138. set Danlist to {"27", "Daniel", "Dan", 12}
  139. set Hoslist to {"28", "Hosea", "Hos", 14}
  140. set Joellist to {"29", "Joel", "Joel", 3}
  141. set Amlist to {"30", "Amos", "Am", 9}
  142. set Obadlist to {"31", "Obadiah", "Obad", 1}
  143. set Jonahlist to {"32", "Jonah", "Jonah", 4}
  144. set Micahlist to {"33", "Micah", "Micah", 7}
  145. set Nahlist to {"34", "Nahum", "Nah", 3}
  146. set Hablist to {"35", "Habakkuk", "Hab", 3}
  147. set Zephlist to {"36", "Zephaniah", "Zeph", 3}
  148. set Haglist to {"37", "Haggai", "Hag", 2}
  149. set Zechlist to {"38", "Zechariah", "Zech", 14}
  150. set Mallist to {"39", "Malachi", "Mal", 4}
  151. set Mattlist to {"40", "Matthew", "Matt", 28}
  152. set Marklist to {"41", "Mark", "Mark", 16}
  153. set Lukelist to {"42", "Luke", "Luke", 24}
  154. set Johnlist to {"43", "John", "John", 21}
  155. set Actslist to {"44", "Acts", "Acts", 28}
  156. set Romlist to {"45", "Romans", "Rom", 16}
  157. set oneCorlist to {"46", "1%20Corinthians", "1 Cor", 16}
  158. set twoCorlist to {"47", "2%20Corinthians", "2 Cor", 13}
  159. set Gallist to {"48", "Galatians", "Gal", 6}
  160. set Epheslist to {"49", "Ephesians", "Ephes", 6}
  161. set Phillist to {"50", "Philippians", "Phil", 4}
  162. set Collist to {"51", "Colossians", "Col", 4}
  163. set oneThesslist to {"52", "1%20Thessalonians", "1 Thess", 5}
  164. set twoThesslist to {"53", "1%20Thessalonians", "2 Thess", 3}
  165. set oneTimlist to {"54", "1%20Timothy", "1 Tim", 6}
  166. set twoTimlist to {"55", "2%20Timothy", "2 Tim", 4}
  167. set Tituslist to {"56", "Titus", "Titus", 3}
  168. set Philemlist to {"57", "Philemon", "Philem", 1}
  169. set Heblist to {"58", "Hebrews", "Heb", 13}
  170. set Jameslist to {"59", "James", "James", 5}
  171. set onePetlist to {"60", "1%20Peter", "1 Pet", 5}
  172. set twoPetlist to {"61", "2%20Peter", "2 Pet", 3}
  173. set oneJohnlist to {"62", "1%20John", "1 John", 5}
  174. set twoJohnlist to {"63", "2%20John", "2 John", 1}
  175. set threeJohnlist to {"64", "3%20John", "3 John", 1}
  176. set Judelist to {"65", "Jude", "Jude", 1}
  177. set Revlist to {"66", "Revelation", "Rev", 22}
  178.  
  179. -- Log which books were chosen
  180. if pickGen is true then
  181.     set bookchosen to bookchosen & Genlist
  182. end if
  183. if pickExod is true then
  184.     set bookchosen to bookchosen & Exodlist
  185. end if
  186. if pickLev is true then
  187.     set bookchosen to bookchosen & Levlist
  188. end if
  189. if pickNum is true then
  190.     set bookchosen to bookchosen & Numlist
  191. end if
  192. if pickDeut is true then
  193.     set bookchosen to bookchosen & Deutlist
  194. end if
  195. if pickJosh is true then
  196.     set bookchosen to bookchosen & Joshlist
  197. end if
  198. if pickJudg is true then
  199.     set bookchosen to bookchosen & Judglist
  200. end if
  201. if pickRuth is true then
  202.     set bookchosen to bookchosen & Ruthlist
  203. end if
  204. if pickoneSam is true then
  205.     set bookchosen to bookchosen & oneSamlist
  206. end if
  207. if picktwoSam is true then
  208.     set bookchosen to bookchosen & twoSamlist
  209. end if
  210. if pickoneKings is true then
  211.     set bookchosen to bookchosen & oneKingslist
  212. end if
  213. if picktwoKings is true then
  214.     set bookchosen to bookchosen & twoKingslist
  215. end if
  216. if pickoneChron is true then
  217.     set bookchosen to bookchosen & oneChronlist
  218. end if
  219. if picktwoChron is true then
  220.     set bookchosen to bookchosen & twoChronlist
  221. end if
  222. if pickEzr is true then
  223.     set bookchosen to bookchosen & Ezrlist
  224. end if
  225. if pickNeh is true then
  226.     set bookchosen to bookchosen & Nehlist
  227. end if
  228. if pickEsth is true then
  229.     set bookchosen to bookchosen & Esthlist
  230. end if
  231. if pickJob is true then
  232.     set bookchosen to bookchosen & Joblist
  233. end if
  234. if pickPs is true then
  235.     set bookchosen to bookchosen & Pslist
  236. end if
  237. if pickProv is true then
  238.     set bookchosen to bookchosen & Provlist
  239. end if
  240. if pickEccles is true then
  241.     set bookchosen to bookchosen & Eccleslist
  242. end if
  243. if pickSong is true then
  244.     set bookchosen to bookchosen & Songlist
  245. end if
  246. if pickIsa is true then
  247.     set bookchosen to bookchosen & Isalist
  248. end if
  249. if pickJer is true then
  250.     set bookchosen to bookchosen & Jerlist
  251. end if
  252. if pickLam is true then
  253.     set bookchosen to bookchosen & Lamlist
  254. end if
  255. if pickEzek is true then
  256.     set bookchosen to bookchosen & Ezeklist
  257. end if
  258. if pickDan is true then
  259.     set bookchosen to bookchosen & Danlist
  260. end if
  261. if pickHos is true then
  262.     set bookchosen to bookchosen & Hoslist
  263. end if
  264. if pickJoel is true then
  265.     set bookchosen to bookchosen & Joellist
  266. end if
  267. if pickAm is true then
  268.     set bookchosen to bookchosen & Amlist
  269. end if
  270. if pickObad is true then
  271.     set bookchosen to bookchosen & Obadlist
  272. end if
  273. if pickJonah is true then
  274.     set bookchosen to bookchosen & Jonahlist
  275. end if
  276. if pickMicah is true then
  277.     set bookchosen to bookchosen & Micahlist
  278. end if
  279. if pickNah is true then
  280.     set bookchosen to bookchosen & Nahlist
  281. end if
  282. if pickHab is true then
  283.     set bookchosen to bookchosen & Hablist
  284. end if
  285. if pickZeph is true then
  286.     set bookchosen to bookchosen & Zephlist
  287. end if
  288. if pickHag is true then
  289.     set bookchosen to bookchosen & Haglist
  290. end if
  291. if pickZech is true then
  292.     set bookchosen to bookchosen & Zechlist
  293. end if
  294. if pickMal is true then
  295.     set bookchosen to bookchosen & Mallist
  296. end if
  297. if pickMatt is true then
  298.     set bookchosen to bookchosen & Mattlist
  299. end if
  300. if pickMark is true then
  301.     set bookchosen to bookchosen & Marklist
  302. end if
  303. if pickLuke is true then
  304.     set bookchosen to bookchosen & Lukelist
  305. end if
  306. if pickJohn is true then
  307.     set bookchosen to bookchosen & Johnlist
  308. end if
  309. if pickActs is true then
  310.     set bookchosen to bookchosen & Actslist
  311. end if
  312. if pickRom is true then
  313.     set bookchosen to bookchosen & Romlist
  314. end if
  315. if pickoneCor is true then
  316.     set bookchosen to bookchosen & oneCorlist
  317. end if
  318. if picktwoCor is true then
  319.     set bookchosen to bookchosen & twoCorlist
  320. end if
  321. if pickGal is true then
  322.     set bookchosen to bookchosen & Gallist
  323. end if
  324. if pickEphes is true then
  325.     set bookchosen to bookchosen & Epheslist
  326. end if
  327. if pickPhil is true then
  328.     set bookchosen to bookchosen & Phillist
  329. end if
  330. if pickCol is true then
  331.     set bookchosen to bookchosen & Collist
  332. end if
  333. if pickoneThess is true then
  334.     set bookchosen to bookchosen & oneThesslist
  335. end if
  336. if picktwoThess is true then
  337.     set bookchosen to bookchosen & twoThesslist
  338. end if
  339. if pickoneTim is true then
  340.     set bookchosen to bookchosen & oneTimlist
  341. end if
  342. if picktwoTim is true then
  343.     set bookchosen to bookchosen & twoTimlist
  344. end if
  345. if pickTitus is true then
  346.     set bookchosen to bookchosen & Tituslist
  347. end if
  348. if pickPhilem is true then
  349.     set bookchosen to bookchosen & Philemlist
  350. end if
  351. if pickHeb is true then
  352.     set bookchosen to bookchosen & Heblist
  353. end if
  354. if pickJames is true then
  355.     set bookchosen to bookchosen & Jameslist
  356. end if
  357. if pickonePet is true then
  358.     set bookchosen to bookchosen & onePetlist
  359. end if
  360. if picktwoPet is true then
  361.     set bookchosen to bookchosen & twoPetlist
  362. end if
  363. if pickoneJohn is true then
  364.     set bookchosen to bookchosen & oneJohnlist
  365. end if
  366. if picktwoJohn is true then
  367.     set bookchosen to bookchosen & twoJohnlist
  368. end if
  369. if pickthreeJohn is true then
  370.     set bookchosen to bookchosen & threeJohnlist
  371. end if
  372. if pickJude is true then
  373.     set bookchosen to bookchosen & Judelist
  374. end if
  375. if pickRev is true then
  376.     set bookchosen to bookchosen & Revlist
  377. end if
  378.  
  379. set totallength to length of bookchosen
  380. set bookamount to (totallength / 4)
  381.  
  382. set chapter to 1
  383.  
  384. if bookchosen is {} then
  385.     set dialogRes3 to display dialog "You have not chosen any books to import." with icon caution buttons {"Okay"} default button "Okay"
  386.     if the button returned of dialogRes3 is "Okay" then
  387.         error number -128
  388.     end if
  389. end if
  390.  
  391. set posid to 1
  392. set bookid to 2
  393. set abbid to 3
  394. set maxchapid to 4
  395.  
  396. set posbible to (item posid) of bookchosen
  397. set book to (item bookid) of bookchosen
  398. set abb to (item abbid) of bookchosen
  399. set maxchapter to (item maxchapid) of bookchosen
  400.  
  401. set dialogbooks to {}
  402. set multiplier to 2
  403. repeat bookamount times
  404.     set dialogbooks to dialogbooks & (item multiplier of bookchosen)
  405.     set multiplier to multiplier + 4
  406. end repeat
  407.  
  408. if dialogchosen is true then
  409.     set dialogRes2 to display dialog "You have chosen these books to import: " & dialogbooks with icon caution buttons {"Exit", "Proceed"} default button "Proceed"
  410.     if the button returned of dialogRes2 is "Exit" then
  411.         error number -128
  412.     end if
  413. end if
  414.  
  415.  
  416. repeat bookamount times
  417.    
  418.     -- Jumping to a new book
  419.     if chapter > maxchapter then
  420.         set posid to (posid + 4)
  421.         set bookid to (bookid + 4)
  422.         set abbid to (abbid + 4)
  423.         set maxchapid to (maxchapid + 4)
  424.        
  425.         set posbible to (item posid) of bookchosen
  426.         set book to (item bookid) of bookchosen
  427.         set abb to (item abbid) of bookchosen
  428.         set maxchapter to (item maxchapid) of bookchosen
  429.        
  430.         set chapter to 1
  431.     end if
  432.    
  433.     repeat maxchapter times
  434.        
  435.         -- COPYING FROM SAFARI
  436.         -- Open Link
  437.         tell application "Safari"
  438.             activate
  439.             delay DelayMed
  440.             tell window 1
  441.                 set current tab to (make new tab with properties {URL:"https://www.biblegateway.com/passage/?search=" & book & "%20" & chapter & "&version=" & translation & "&interface=print"})
  442.             end tell
  443.         end tell
  444.        
  445.         delay DelayLong
  446.        
  447.         -- Copy all
  448.         tell application "System Events"
  449.             keystroke "a" using command down
  450.             delay DelayShort
  451.             keystroke "c" using command down
  452.         end tell
  453.        
  454.         delay DelayShort
  455.        
  456.         tell application "Safari"
  457.             activate
  458.             tell window 1
  459.                 close current tab
  460.             end tell
  461.         end tell
  462.        
  463.         -- ACTIVATE ATOM
  464.         tell application "Atom"
  465.             activate
  466.         end tell
  467.        
  468.         do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & textX & "," & textY
  469.        
  470.        
  471.         delay DelayMed
  472.        
  473.         tell application "System Events"
  474.             delay DelayShort
  475.             keystroke "v" using command down
  476.             delay DelayShort
  477.            
  478.             keystroke "f" using command down
  479.             keystroke book & " " & chapter
  480.            
  481.             key code 48 -- tab
  482.             delay DelayShort
  483.             keystroke "a" using command down
  484.             key code 51 -- delete
  485.            
  486.             key code 36 using command down
  487.            
  488.             -- Delete Version name
  489.            
  490.             keystroke "f" using command down
  491.             keystroke "English Standard Version"
  492.            
  493.             key code 48 -- tab
  494.             delay DelayShort
  495.             keystroke "a" using command down
  496.             key code 51 -- delete
  497.            
  498.             key code 36 using command down
  499.            
  500.             -- Delete Bottom
  501.             -- #1
  502.            
  503.             keystroke "f" using command down
  504.             keystroke " (ESV)"
  505.            
  506.             key code 48 -- tab
  507.             delay DelayShort
  508.             keystroke "a" using command down
  509.             key code 51 -- delete
  510.            
  511.             key code 36 using command down
  512.            
  513.             -- #2
  514.             keystroke "f" using command down
  515.             keystroke "The Holy Bible, . ESV® Text Edition: 2016. Copyright © 2001 by Crossway Bibles, a publishing ministry of Good News Publishers."
  516.             delay DelayShort
  517.            
  518.             key code 48 -- tab
  519.             delay DelayShort
  520.             keystroke "a" using command down
  521.             key code 51 -- delete
  522.             delay DelayMed
  523.            
  524.             key code 36 using command down
  525.            
  526.             -- #3
  527.             keystroke "f" using command down
  528.             keystroke "Twitter"
  529.            
  530.             key code 48 -- tab
  531.             delay DelayShort
  532.             keystroke "a" using command down
  533.             key code 51 -- delete
  534.            
  535.             key code 36 using command down
  536.            
  537.             -- #4
  538.             keystroke "f" using command down
  539.             keystroke "Facebook"
  540.            
  541.             key code 48 -- tab
  542.             delay DelayShort
  543.             keystroke "a" using command down
  544.             key code 51 -- delete
  545.            
  546.             key code 36 using command down
  547.            
  548.             -- #5
  549.             keystroke "f" using command down
  550.             keystroke "Email"
  551.            
  552.             key code 48 -- tab
  553.             delay DelayShort
  554.             keystroke "a" using command down
  555.             key code 51 -- delete
  556.            
  557.             key code 36 using command down
  558.            
  559.            
  560.             -- FIX FIRST NUMBER
  561.            
  562.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & textX & "," & textY
  563.            
  564.             delay DelayShort
  565.             key code 126 using command down --top of page
  566.             delay DelayShort
  567.             repeat 3 times
  568.                 key code 125 using shift down -- delete top lines
  569.             end repeat
  570.             key code 51 --delete
  571.             key code 124 --move right
  572.             delay DelayShort
  573.             key code 51 -- delete
  574.             if chapter > 9 then
  575.                 delay DelayShort
  576.                 key code 124 --move right
  577.                 delay DelayShort
  578.                 key code 51 -- delete
  579.             end if
  580.            
  581.             if chapter > 99 then
  582.                 delay DelayShort
  583.                 key code 124 --move right
  584.                 delay DelayShort
  585.                 key code 51 -- delete
  586.             end if
  587.            
  588.             delay DelayShort
  589.             keystroke "1"
  590.            
  591.            
  592.             -- START SEARCH
  593.             delay DelayMed
  594.             keystroke "f" using command down
  595.             delay DelayMed
  596.            
  597.             -- Enable Regrex
  598.            
  599.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & regX & "," & regY
  600.            
  601.            
  602.             delay DelayShort
  603.             keystroke "f" using command down
  604.             delay DelayShort
  605.            
  606.             -- ENTER REGREX CODE
  607.             keystroke "([0-9]|[1-9][0-9]|100)"
  608.             key code "26" using {shift down, option down} -- write "\"
  609.             keystroke "s"
  610.             delay DelayMed
  611.             key code 48 -- tab
  612.             delay DelayShort
  613.             keystroke "a" using command down
  614.             key code 51 -- delete
  615.            
  616.             delay DelayShort
  617.             key code "26" using {shift down, option down} -- write "\"
  618.             keystroke "n "
  619.             key code "26" using {shift down, option down} -- write "\"
  620.             keystroke "n###### " & "v$1 "
  621.             key code "26" using {shift down, option down} -- write "\"
  622.             keystroke "n"
  623.             delay DelayMed
  624.            
  625.             -- FORMAT USING REGREX 
  626.            
  627.             key code 36 using command down
  628.            
  629.             -- DELETE DOUBLE LINES
  630.            
  631.             delay DelayMed
  632.             keystroke "f" using command down
  633.             delay DelayShort
  634.             key code 51 -- delete
  635.             delay DelayShort
  636.             key code "26" using {shift down, option down} -- write "\"
  637.             keystroke "n*"
  638.             key code "26" using {shift down, option down} -- write "\"
  639.             keystroke "n"
  640.            
  641.             delay DelayShort
  642.             key code 48 -- tab
  643.             delay DelayShort
  644.             keystroke "a" using command down
  645.             key code 51 -- delete
  646.             delay DelayShort
  647.             key code "26" using {shift down, option down} -- write "\"
  648.             keystroke "n"
  649.             delay DelayMed
  650.            
  651.             key code 36 using command down
  652.            
  653.             -- ENTER CHAPTER NAVIGATION TOP
  654.             delay DelayShort
  655.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & textX & "," & textY
  656.             delay DelayMed
  657.            
  658.             key code 126 using command down --top of page
  659.            
  660.             delay DelayShort
  661.            
  662.             keystroke "# " & book & " " & chapter
  663.             key code "36"
  664.             key code "36"
  665.            
  666.             delay DelayShort
  667.            
  668.             if (chapter - 1) > 0 then
  669.                 if 9 > (chapter - 1) then
  670.                     keystroke "[[" & abb & "-" & "0" & (chapter - 1) & "|<- " & book & " " & "0" & (chapter - 1) & " ]] | "
  671.                 else
  672.                     keystroke "[[" & abb & "-" & (chapter - 1) & "|<- " & book & " " & (chapter - 1) & " ]] | "
  673.                 end if
  674.             end if
  675.            
  676.             keystroke "[[_" & book & "|" & book & "]]"
  677.            
  678.             if maxchapter > (chapter) then
  679.                 if 9 > (chapter + 1) then
  680.                     keystroke " | [[" & abb & "-" & "0" & (chapter + 1) & "|" & book & " " & "0" & (chapter + 1) & " ->]]"
  681.                 else
  682.                     keystroke " | [[" & abb & "-" & (chapter + 1) & "|" & book & " " & (chapter + 1) & " ->]]"
  683.                 end if
  684.             end if
  685.            
  686.            
  687.             key code "36"
  688.             keystroke "***"
  689.            
  690.             -- ENTER NAVIGATION BOTTOM
  691.             key code 125 using command down --bottom of page
  692.            
  693.             delay DelayShort
  694.            
  695.             key code "36"
  696.             keystroke "***"
  697.             key code "36"
  698.            
  699.             if (chapter - 1) > 0 then
  700.                 if 9 > (chapter - 1) then
  701.                     keystroke "[[" & abb & "-" & "0" & (chapter - 1) & "|<- " & book & " " & "0" & (chapter - 1) & " ]] | "
  702.                 else
  703.                     keystroke "[[" & abb & "-" & (chapter - 1) & "|<- " & book & " " & (chapter - 1) & " ]] | "
  704.                 end if
  705.             end if
  706.            
  707.             keystroke "[[_" & book & "|" & book & "]]"
  708.            
  709.             if maxchapter > (chapter) then
  710.                 if 9 > (chapter + 1) then
  711.                     keystroke " | [[" & abb & "-" & "0" & (chapter + 1) & "|" & book & " " & "0" & (chapter + 1) & " ->]]"
  712.                 else
  713.                     keystroke " | [[" & abb & "-" & (chapter + 1) & "|" & book & " " & (chapter + 1) & " ->]]"
  714.                 end if
  715.             end if
  716.            
  717.             -- Disable Regrex
  718.            
  719.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & regX & "," & regY
  720.            
  721.            
  722.             -- Delete Encoding
  723.             if book contains "%20" then
  724.                 keystroke "f" using command down
  725.                 delay DelayShort
  726.                 key code 51 -- delete
  727.                 delay DelayShort
  728.                 keystroke "%20"
  729.                
  730.                 delay DelayShort
  731.                 key code 48 -- tab
  732.                 delay DelayShort
  733.                 keystroke "a" using command down
  734.                 key code 51 -- delete
  735.                 delay DelayShort
  736.                 keystroke " "
  737.                 delay DelayMed
  738.                
  739.                 key code 36 using command down
  740.             end if
  741.            
  742.             -- SAVING DIALOG
  743.             if savedialog is true then
  744.                 set dialogResult to display dialog "Do you want to save this chapter?" with icon caution buttons {"Exit", "Save"} default button "Save" giving up after 3
  745.                 if the button returned of dialogResult is "Exit" then
  746.                     error number -128
  747.                 end if
  748.                
  749.             end if
  750.            
  751.             -- CLICK INTO TEXT FIELD
  752.            
  753.             delay DelayMed
  754.            
  755.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & textX & "," & textY
  756.            
  757.             delay DelayShort
  758.            
  759.             -- SAVE
  760.             delay DelayMed
  761.             keystroke "s" using {shift down, command down}
  762.             delay DelayMed
  763.            
  764.            
  765.             -- Choose top folder           
  766.             if chapter = 1 then
  767.                 do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & folderX & "," & folderY
  768.                 delay DelayMed
  769.                 do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & newX & "," & newY
  770.                 delay DelayShort
  771.                
  772.                 -- Name new book folder
  773.                 keystroke posbible & " - " & book
  774.                 delay DelayShort
  775.                 if book contains "%20" then
  776.                     key code 123 using command down -- left
  777.                     repeat 9 times
  778.                         key code 124 -- right
  779.                         delay DelayShort
  780.                     end repeat
  781.                     repeat 3 times
  782.                         key code 51 -- delete
  783.                         delay DelayShort
  784.                     end repeat
  785.                    
  786.                     keystroke " "
  787.                     DelayMed
  788.                 end if
  789.                
  790.                 key code 36
  791.                 delay DelayShort
  792.             end if
  793.            
  794.             delay DelayLong
  795.            
  796.             -- Save file               
  797.             keystroke "a" using command down
  798.             delay DelayShort
  799.             keystroke abb & "-"
  800.             if chapter < 10 then
  801.                 keystroke "0"
  802.             end if
  803.             keystroke chapter
  804.             delay DelayShort
  805.             keystroke ".md"
  806.             delay DelayLong
  807.             key code 36
  808.             delay DelayMed
  809.            
  810.             -- CLICK INTO TEXT FIELD
  811.            
  812.             delay DelayShort
  813.            
  814.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & textX & "," & textY
  815.            
  816.             delay DelayShort
  817.            
  818.             -- BLANK CANVA
  819.            
  820.             keystroke "a" using {command down}
  821.            
  822.             delay DelayShort
  823.             key code 51 --delete
  824.            
  825.             delay DelayMed
  826.            
  827.            
  828.         end tell
  829.        
  830.         set chapter to chapter + 1
  831.        
  832.     end repeat
  833.    
  834.     if bigdialog is true then
  835.         set dialogR4 to display dialog "Do you want to continue?" with icon caution buttons {"Exit", "Continue"} default button "Continue" giving up after 5
  836.         if the button returned of dialogR4 is "Exit" then
  837.             error number -128
  838.         end if
  839.        
  840.     end if
  841.    
  842. end repeat
  843.  
  844. if shutdown is true then
  845.     delay 10
  846.     tell application "Atom"
  847.         quit
  848.     end tell
  849.    
  850.     delay 10
  851.    
  852.     tell application "Safari"
  853.         quit
  854.     end tell
  855.    
  856.     delay 10
  857.    
  858.     tell application "Finder"
  859.         shut down
  860.     end tell
  861.    
  862. else
  863.     display dialog "Done Importing!" with icon note
  864.    
  865. end if
Advertisement
RAW Paste Data Copied
Advertisement