Advertisement
selfire_

Bible to Obsidian

Jul 6th, 2020
1,950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- DEFINITIONS
  2. set translation to "ESV"
  3. set booklist to {"1 Peter", "2 Peter", "1 John", "2 John", "3 John"} -- if I want to export multiple books at one go, I can enter them here
  4. set bookamount to count of booklist
  5. set chapterlist to {5, 3, 5, 1, 1} -- The chapters of the books above
  6.  
  7. -- When there is a space in the book title, it needs to be encoded for the link to work.
  8. set encodeq to true
  9. if encodeq is true then
  10.     set encodelist to {"1%20Peter", "2%20Peter", "1%20John", "2%20John", "3%20John"}
  11. end if
  12.  
  13. set chapter to 1
  14. set listid to 1
  15. set encodeid to 1
  16.  
  17. set DelayStart to 4
  18. set DelayLong to 2
  19. set DelayMed to 1
  20. set DelayShort to 0.2
  21.  
  22. set taboneX to 134
  23. set taboneY to 60
  24.  
  25. set tabtwoX to 335
  26. set tabtwoY to 60
  27.  
  28. -- #PREPARE
  29.  
  30. -- ##STARTUP DIALOGUE
  31. (* display dialog "Are Safari and Atom open?" buttons {"No", "Yes"} default button "Yes"
  32.  
  33. if {button returned:"No"} then *)
  34.  
  35. -- SAFARI
  36.  
  37. tell application "Safari"
  38.     activate
  39. end tell
  40.  
  41. delay DelayStart
  42.  
  43. -- START ATOM
  44.  
  45. tell application "Atom"
  46.     activate
  47.     delay DelayStart
  48. end tell
  49.  
  50. delay DelayLong
  51.  
  52. -- end if
  53.  
  54. (* if {button returned:"Yes"} then
  55.    
  56.     tell application "Atom"
  57.         activate
  58.         delay DelayMed
  59.     end tell
  60.    
  61. end if *)
  62.  
  63. -- ENABLE REGREX
  64.  
  65. tell application "System Events"
  66.     keystroke "f" using command down
  67.     delay DelayLong
  68.    
  69.     set secondX to 1121
  70.     set secondY to 674
  71.    
  72.     do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & secondX & "," & secondY
  73.    
  74.     delay DelayMed
  75.    
  76.     -- CREATE NEW TAB AND CHOOSE TAB ONE
  77.    
  78.     tell application "System Events"
  79.         keystroke "n" using command down
  80.         DelayMed
  81.         do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & taboneX & "," & taboneY
  82.     end tell
  83.    
  84. end tell
  85.  
  86. delay DelayMed
  87.  
  88. -- #BOOK LOOP
  89.  
  90. repeat bookamount times
  91.    
  92.     -- DEFINITIONS
  93.    
  94.     set book to (item listid) of booklist
  95.     set maxchapter to (item listid) of chapterlist
  96.     if encodeq is true then
  97.         set encodelink to (item encodeid) of encodelist
  98.        
  99.     end if
  100.    
  101.     if chapter > maxchapter then
  102.         if encodeq is true then
  103.             set encodeid to encodeid + 1
  104.             set encodelink to (item encodeid) of encodelist
  105.         end if
  106.        
  107.         set listid to listid + 1
  108.         set book to (item listid) of booklist
  109.         set maxchapter to (item listid) of chapterlist
  110.         set chapter to 1
  111.     end if
  112.    
  113.    
  114.     delay DelayStart
  115.    
  116.     -- #LOOP
  117.    
  118.     repeat until (chapter > maxchapter)
  119.        
  120.         -- OPEN SAFARI TAB
  121.        
  122.         tell application "Safari"
  123.             activate
  124.             delay DelayMed
  125.             tell window 1
  126.                 if encodeq is false then
  127.                     set current tab to (make new tab with properties {URL:"https://www.biblegateway.com/passage/?search=" & book & "%20" & chapter & "&version=" & translation & "&interface=print"})
  128.                 end if
  129.                
  130.                 if encodeq is true then
  131.                     set current tab to (make new tab with properties {URL:"https://www.biblegateway.com/passage/?search=" & encodelink & "%20" & chapter & "&version=" & translation & "&interface=print"})
  132.                 end if
  133.             end tell
  134.         end tell
  135.        
  136.         delay DelayStart
  137.        
  138.         -- COPY EVERYTHING
  139.        
  140.         tell application "System Events"
  141.             keystroke "a" using command down
  142.             delay DelayShort
  143.             keystroke "c" using command down
  144.         end tell
  145.        
  146.         delay DelayMed
  147.        
  148.         tell application "Safari"
  149.             activate
  150.             tell window 1
  151.                 close current tab
  152.             end tell
  153.         end tell
  154.        
  155.         delay DelayMed
  156.        
  157.         -- OPEN ATOM
  158.        
  159.         tell application "Atom"
  160.             activate
  161.         end tell
  162.        
  163.         delay DelayMed
  164.        
  165.         tell application "SizeUp" to do action Full Screen
  166.        
  167.         DelayShort
  168.        
  169.         -- CLICK INTO TEXT FIELD
  170.        
  171.         do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & taboneX & "," & taboneY
  172.        
  173.         set firstX to 46
  174.         set firstY to 86
  175.        
  176.         do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & firstX & "," & firstY
  177.        
  178.         delay DelayMed
  179.        
  180.         -- PASTE INTO ATOM
  181.        
  182.         tell application "System Events"
  183.             --  keystroke "a" using command down
  184.             --  delay DelayShort
  185.             -- key code 51 -- delete
  186.             delay DelayShort
  187.             keystroke "v" using command down
  188.             delay DelayShort
  189.            
  190.             -- CLEAN TOP UP
  191.            
  192.             key code 126 using command down --top of page
  193.             delay DelayShort
  194.             repeat 3 times
  195.                 key code 125 using shift down
  196.                 delay DelayShort
  197.             end repeat
  198.             key code 51 --delete
  199.             delay DelayShort
  200.            
  201.             -- CLEAN BOTTOM UP
  202.             key code 125 using command down --bottom of page
  203.             repeat 7 times
  204.                 key code 126 using shift down
  205.                 delay DelayShort
  206.             end repeat
  207.             -- repeat 5 times -- Proverbs: 7 times
  208.             key code 51 --delete
  209.             delay DelayShort
  210.             -- end repeat
  211.            
  212.             -- FIX FIRST NUMBER
  213.            
  214.             key code 126 using command down --top of page
  215.             delay DelayShort
  216.             key code 124 --move right
  217.             delay DelayShort
  218.             key code 51 -- delete
  219.             if chapter > 9 then
  220.                 delay DelayShort
  221.                 key code 124 --move right
  222.                 delay DelayShort
  223.                 key code 51 -- delete
  224.             end if
  225.             delay DelayShort
  226.             keystroke "1"
  227.            
  228.            
  229.             -- START SEARCH
  230.             delay DelayMed
  231.             keystroke "f" using command down
  232.             delay DelayMed
  233.            
  234.             -- ENTER REGREX CODE
  235.             keystroke "([0-9]|[1-9][0-9]|100)"
  236.             key code "26" using {shift down, option down} -- write "\"
  237.             keystroke "s"
  238.             delay DelayMed
  239.             key code 48 -- tab
  240.             delay DelayShort
  241.             keystroke "a" using command down
  242.             key code 51 -- delete
  243.            
  244.             delay DelayShort
  245.             key code "26" using {shift down, option down} -- write "\"
  246.             keystroke "n "
  247.             key code "26" using {shift down, option down} -- write "\"
  248.             keystroke "n### " & book & " " & chapter & ":$1"
  249.             key code "26" using {shift down, option down} -- write "\"
  250.             keystroke "n"
  251.             delay DelayMed
  252.            
  253.             -- FORMAT USING REGREX 
  254.            
  255.             key code 36 using command down
  256.            
  257.             -- DELETE DOUBLE LINES
  258.            
  259.             delay DelayMed
  260.             keystroke "f" using command down
  261.             delay DelayShort
  262.             key code 51 -- delete
  263.             delay DelayShort
  264.             key code "26" using {shift down, option down} -- write "\"
  265.             keystroke "n*"
  266.             key code "26" using {shift down, option down} -- write "\"
  267.             keystroke "n"
  268.            
  269.             delay DelayShort
  270.             key code 48 -- tab
  271.             delay DelayShort
  272.             keystroke "a" using command down
  273.             key code 51 -- delete
  274.             delay DelayShort
  275.             key code "26" using {shift down, option down} -- write "\"
  276.             keystroke "n"
  277.             delay DelayMed
  278.            
  279.             key code 36 using command down
  280.            
  281.             -- DELETE LINE ON TOP
  282.             delay DelayShort
  283.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & firstX & "," & firstY
  284.             delay DelayShort
  285.             key code 126 using command down --top of page
  286.             delay DelayShort
  287.             keystroke "## " & book & " " & chapter
  288.             delay DelayShort
  289.            
  290.             -- CLEAN UP BOTTOM
  291.             key code 125 using command down --bottom of page
  292.             delay DelayShort
  293.             repeat 2 times
  294.                 key code 36
  295.                 DelayShort
  296.             end repeat
  297.            
  298.             key code 51 --delete
  299.             delay DelayShort
  300.            
  301.             --- ADD LINE
  302.            
  303.             keystroke "***"
  304.             delay DelayShort
  305.            
  306.             -- CUT ALL
  307.             keystroke "a" using command down
  308.             delay DelayShort
  309.             keystroke "x" using command down
  310.             delay DelayShort
  311.            
  312.             -- PASTE IN NEW TAB
  313.            
  314.             do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & tabtwoX & "," & tabtwoY
  315.            
  316.             keystroke "v" using command down
  317.             DelayShort
  318.             repeat 2 times
  319.                 key code 36
  320.                 DelayShort
  321.             end repeat
  322.             delay DelayMed
  323.            
  324.             if chapter = maxchapter then
  325.                
  326.                 -- SAVE TAB TWO
  327.                
  328.                 keystroke "s" using {shift down, command down}
  329.                 delay DelayMed
  330.                 keystroke book & ".md"
  331.                 delay DelayMed
  332.                 key code 36
  333.                 delay DelayMed
  334.                
  335.                 -- CLOSE TAB TWO AND NEW TAB
  336.                 keystroke "w" using command down
  337.                 delay DelayMed
  338.                 keystroke "n" using command down
  339.                 delay DelayMed
  340.                 do shell script "eval $(/usr/libexec/path_helper -s); cliclick c:" & taboneX & "," & taboneY
  341.                
  342.             end if
  343.            
  344.            
  345.         end tell
  346.        
  347.         -- CHAPTER COUNT
  348.        
  349.         set chapter to chapter + 1
  350.         log chapter
  351.        
  352.     end repeat
  353. end repeat
  354.  
  355. -- NOTIFICATION
  356. -- display dialog "Transferred books of the bible!"
  357.  
  358. tell application "Atom"
  359.     quit
  360. end tell
  361.  
  362. tell application "Safari"
  363.     quit
  364. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement