Applescript headache with copy/pasting

Discussion in 'Mac Programming' started by Ikard, Oct 20, 2011.

  1. Ikard macrumors newbie

    Joined:
    Oct 20, 2011
    #1
    Essentially what I'm trying to do is rather simple. Or at least, it should be...

    Code:
    set rand1 to random number from 20000 to 40000
    set rand4 to random number from 1000 to 10000
    set rand5 to random number from 30000 to 50000
    set theFile to choose file with prompt "Select an image (in jpeg format dood!)"
    tell application "TextEdit" to open theFile
    tell application "TextEdit" to activate
    
    tell application "System Events" to tell process "TextEdit"
    	repeat rand1 times
    		key code 125
    	end repeat
    	shift key down
    	repeat 100 times
    		key code 125
    	end repeat
    	shift key up
    	key code 7 using command down
    	repeat rand4 times
    		key code 125
    	end repeat
    	key code 9 using command down
    end tell
    end
    
    the intent of this little gem is to open a jpeg in textedit, select a random block of 100 lines, cut it, and paste it to another random location. instead... nothing seems to happen at all. sure, textedit opens, but that's about it.

    can anyone help?
     
  2. Ikard thread starter macrumors newbie

    Joined:
    Oct 20, 2011
    #2
    And, yes, before anyone asks, I do know I have more random numbers than I strictly need.
     
  3. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #3
    I assume you are trying to build a fuzzer, and my one piece of advice here is that you are very much using the wrong tool. You have esentially reduced this to text manipulation, and a scripting language like Python, Perl, or Ruby will be far faster, and far more reliable.
     

Share This Page