Autohotkey to Applescript

Discussion in 'Mac Programming' started by Wonky, May 22, 2012.

  1. macrumors newbie

    May 22, 2012
    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") ?

    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!
  2. kryten2, May 22, 2012
    Last edited: May 22, 2012

    macrumors 6502a

    Mar 17, 2012
    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"
    	tell application "System Events"
    		keystroke "x"
    		--delay is in seconds so 0.00001 etc
    		delay 1.0E-5
    		keystroke "x"
    	end tell
    end tell
  3. Wonky, May 22, 2012
    Last edited: May 22, 2012

    thread starter macrumors newbie

    May 22, 2012
    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.
  4. macrumors 6502a

    Mar 17, 2012
  5. macrumors newbie

    Jul 20, 2012
    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}
    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

    it's a pretty long script and i dont have any idea on how to do any of this :(

Share This Page