PDA

View Full Version : Autohotkey to Applescript




Wonky
May 22, 2012, 06:01 PM
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
May 22, 2012, 08:02 PM
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


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

Wonky
May 22, 2012, 08:16 PM
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.




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.

kryten2
May 22, 2012, 10:21 PM
Depends on what version of OS X you're running. Take a look at this link :
http://superuser.com/questions/153890/assign-a-shortcut-to-running-a-script-in-os-x
I think it provides the answers you're looking for.

sesepark
Jul 20, 2012, 04:04 AM
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 :(