keystroke command

is there anyway to add random numbers to a keystroke command
i want to change the port on transmission at regular intervals to random number
i cant seem to keystroke a variable

here’s my code


tell application "Transmission"
	activate
end tell

tell application "System Events"
	if UI elements enabled then
		repeat
			tell process "Transmission"
				set frontmost to true
			end tell
			
			keystroke "5"
			keystroke "0"
			keystroke "0"
			keystroke "0"
			keystroke "1"
			keystroke return
			delay 240
			keystroke "6"
			keystroke "9"
			keystroke "9"
			
			keystroke "1"
			keystroke return
			delay 40
		end repeat
		
		
	else
		tell application "System Preferences"
			activate
			set current pane to pane "com.apple.preference.universalaccess"
			display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
		end tell
	end if
end tell
tell application "TextEdit"
	activate
end tell


Model: MacBook Pro
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi Rohan

will something like this help:

set n to random number 9
tell application "System Events"
	activate
	keystroke n
	display dialog n
end tell

This really dosen’t seem to be working it seems the keystroke command dosent accept vars it dosent actually do anything

Hi,

this

tell application "System Events"
  -- if UI elements enabled then 
       repeat
           tell process "Transmission"
               set frontmost to true
           end tell
           
           keystroke "5"
           keystroke "0"
           keystroke "0"
           keystroke "0"
           keystroke "1"
           keystroke return
...

can be replaced by (assuming a random number between 10000 and 50000)

tell application "System Events"
	repeat
	tell process "Transmission"
		set a to (random number from 10000 to 50000) as string
		run script "keystroke " & quote & a & quote & " & return" -- this trick makes it possible to use a variable
...

instead of the delay commands it would be better to use a stay open script with an idle handler

Brilliant!

Hello

I don’t understand the problem.

When I run this script:

set a to (random number from 10000 to 50000) as string

tell application "TextEdit" to activate
tell application "System Events" to tell process "TextEdit"
	
	keystroke a
end tell

it works flawlessly.

I wonder if you took care to put your process at front.

Yvan KOENIG (from FRANCE vendredi 9 mars 2007 16:53:39)

hm, Yvan,

of course I tried it exactly your way with TextEdit and it didn’t work,
so I had the idea to use the second-level evaluation