Frogger3140

YWOTPaste FIXED

Jul 21st, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. str_replace by Bruce Phillips from MacScripter
  3. http://macscripter.net/viewtopic.php?id=18551
  4. *)
  5.  
  6.  
  7. -- find : Text (or list of text) to be found
  8. -- replace : Text (or list of text) to replace with
  9. -- subject : Text (or list of text) to be searched
  10. on str_replace(find, replace, subject)
  11.     set prevTIDs to text item delimiters of AppleScript
  12.     set returnList to true
  13.    
  14.     -- This wouldn't make sense (you could have it raise an error instead)
  15.     if class of find is not list and class of replace is list then return subject
  16.    
  17.     if class of find is not list then set find to {find}
  18.     if class of subject is not list then ¬
  19.         set {subject, returnList} to {{subject}, false}
  20.    
  21.     set findCount to count find
  22.     set usingReplaceList to class of replace is list
  23.    
  24.     try
  25.         repeat with i from 1 to (count subject)
  26.             set thisSubject to item i of subject
  27.            
  28.             repeat with n from 1 to findCount
  29.                 set text item delimiters of AppleScript to item n of find
  30.                 set thisSubject to text items of thisSubject
  31.                
  32.                 if usingReplaceList then
  33.                     try
  34.                         item n of replace
  35.                     on error
  36.                         "" -- `replace` ran out of items
  37.                     end try
  38.                 else
  39.                     replace
  40.                 end if
  41.                
  42.                 set text item delimiters of AppleScript to result
  43.                 set thisSubject to "" & thisSubject
  44.             end repeat
  45.            
  46.             set item i of subject to thisSubject
  47.         end repeat
  48.     end try
  49.    
  50.     set text item delimiters of AppleScript to prevTIDs
  51.     if not returnList then return beginning of subject
  52.     return subject
  53. end str_replace
  54.  
  55.  
  56. (*
  57. This script pastes whatever myPaste is set to into YWOT, with enter.
  58.  
  59. Please don't use this to grief.
  60. *)
  61.  
  62. set myPaste to "" --paste stuff here or just set to the clipboard
  63. set keystrokeSpeed to 0.1 --set to 0.2 if some letters are skipped while pasting into YWOT
  64.  
  65. set myExplodedPaste to str_replace("
  66. ", return, every character of myPaste)
  67.  
  68. set i to 0
  69.  
  70. display dialog "This will take approximately " & (length of myPaste * keystrokeSpeed) & " seconds to complete."
  71.  
  72. if the button returned in the result is "OK" then
  73.     tell application "Safari"
  74.         activate
  75.         tell application "System Events"
  76.             repeat length of myPaste times
  77.                 set i to i + 1
  78.                 key down item i of myExplodedPaste
  79.                 key up item i of myExplodedPaste
  80.                 delay keystrokeSpeed
  81.             end repeat
  82.             key down return
  83.             key up return
  84.         end tell
  85.     end tell
  86. end if
Advertisement
Add Comment
Please, Sign In to add comment