Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wonky

macrumors newbie
Original poster
May 22, 2012
2
0
Hello, everyone. I need help converting a script from Autohotkey to Applescript. I'm not sure if an exact conversion is possible, but I would like to at least simulate a similar behavior. Here's the code in Autohotkey's language:

~CapsLock::Suspend, % GetKeyState("CapsLock","t") ?

c::
While GetKeyState("c","P")
{
send, {x down}
sleep, 10
send, {x up}
sleep, 25
send, {x down}
sleep, 10
send, {x up}
sleep, 25
}

Basically, I need the x keystroke to be pressed twice fairly quickly. Any assistance would be greatly appreciated. Thanks!
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
I googled Autohotkey. Looks like a Windows thingy. "System Events" will send a key code or a keystroke to the frontmost application.So, you have to make sure that application is frontmost—activate it, in AppleScript parlance. More info can be found in the System Events dictionary --> Processes Suite.

keystroke v : cause the target process to behave as if keystrokes were entered
keystroke text : The keystrokes to be sent.
[using command down/control down/option down/shift down] : modifiers with which the keystrokes are to be entered


Code:
tell application "The application"
	activate
	tell application "System Events"
		keystroke "x"
		--delay is in seconds so 0.00001 etc
		delay 1.0E-5
		keystroke "x"
	end tell
end tell
 
Last edited:

Wonky

macrumors newbie
Original poster
May 22, 2012
2
0
I googled Autohotkey. Looks like a Windows thingy. "System Events" will send a key code or a keystroke to the frontmost application.So, you have to make sure that application is frontmost—activate it, in AppleScript parlance. More info can be found in the System Events dictionary --> Processes Suite.




Code:
tell application "The application"
	activate
	tell application "System Events"
		keystroke "x"
		--delay is in seconds so 0.00001 etc
		delay 1.0E-5
		keystroke "x"
	end tell
end tell

Thank you, kryten2. When I ran the script in the Applescript environment, the output was what I was looking for. I've specified the application I'd like the script to be run in, but how do I bind this script to a key? Thanks again.
 
Last edited:

sesepark

macrumors newbie
Jul 20, 2012
1
0
I have a smiliar question

Sorry I am really new to this scripting thing but I've been an apple devotee for several years now.

There's a sepcific script from auto clicker that I need translated into apple script. is this possible? is there an easy way of translating a script? Here is the script from auto clikerr:

#IfWinActive, Diablo III
#MaxThreadsPerHotkey 2
#SingleInstance force
F1:: ;Gear Switcher
BlockInput, On
send, {SHIFTDOWN}
MouseClick, left, 1192,1034
send, {SHIFTUP}
; Open Inventory
Send, {SPACE}
Send, {I}
; Rings
MouseClick, right, 1435, 748
Send, {ALTDOWN}
MouseClick, right, 1481, 753
send, {ALTUP}
;Sword
MouseClick, right, 1438, 826
; Ammy
MouseClick, right, 1485, 803
; Belt
MouseClick, right, 1484, 843
; Shield
MouseClick, right, 1537, 828
; Shoulders
MouseClick, right, 1586, 827
; Chest
MouseClick, right, 1621, 828
; Bracers
MouseClick, right, 1683, 828
; Pants
MouseClick, right, 1724, 828
; Helm
MouseClick, right, 1774, 831
; Gloves
MouseClick, right, 1822, 832
; Boots
MouseClick, right, 1876, 840
; Reset Position
Send, {SPACE}
BlockInput, Off
return

it's a pretty long script and i dont have any idea on how to do any of this :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.