noob help: Applescript - System Events, keystroke...

Discussion in 'Mac Programming' started by jakdominance, Nov 18, 2008.

  1. jakdominance macrumors member

    jakdominance

    Joined:
    Nov 18, 2008
    #1
    I'm not exactly a programmer, but i've touched my toes, ok, my smallest toe, into the depths a little. I've worked with pretty simple HTML and CSS, but that's pretty different from programming. Anyways, I've been looking for a way to use Spaces with Quicksilver (i know, not programming at all, keep reading) and I found a way using Applescript from here. Essentially he used the "Switch directly to a space" button (in system prefs) and used this script

    Code:
    tell application "System Events" to keystroke "1" using control down
    as a quicksilver trigger to go to Space 1. Very simple, but I wanted to use mouse gestures instead with "Switch between spaces"

    Code:
    tell application "System Events" to keystroke "left" using command down
    doesn't work, probably because Applescript doesn't understand "left", I think. Is there a way (ASCII?) to make it work? Any better ideas for
     
  2. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
    #2
    Full Key Codes suggests 28 for the left arrow:
    Code:
    tell application "System Events" to key code 28 using control down
    But it doesn't seem to work for me. :confused:
     
  3. jakdominance thread starter macrumors member

    jakdominance

    Joined:
    Nov 18, 2008
    #3
    first you need the command "keystroke" for it to work.
    Is it like ASCII code? cause then it may need to be:

    Code:
    tell application "System Events" to keystroke (key code 28) using control down
    however tried it and it doesn't work... hmmm...
     
  4. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
    #4
    In order to use key codes you have to use "key code" instead to keystroke. Trust me. I've been using it a few times so far.
     
  5. jakdominance thread starter macrumors member

    jakdominance

    Joined:
    Nov 18, 2008
    #5
    soudesuka.....

    Thanks!!! :D

    still doesn't work, tho... grrrr
     
  6. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
    #6
    Got it! After a bit of Googling, I was able to find the real key codes for the arrow keys (Full Key Codes was wrong, it seems). They are:

    key code 123 -- left arrow Key
    --
    key code 124 -- right arrow Key
    --
    key code 126 -- up arrow Key
    --
    key code 125 -- down arrow Key

    Have fun ;)
     
  7. jakdominance thread starter macrumors member

    jakdominance

    Joined:
    Nov 18, 2008
    #7
    oops

    well, I would try it, but i just tried downloading a lean version from Google code projects and, well, it's lean. Really lean. So I can't until i re-download quicksilver again. oops. but later, cause it's late here where i live and i need sleep.
     
  8. jakdominance thread starter macrumors member

    jakdominance

    Joined:
    Nov 18, 2008
    #8
    Did It

    I did it. Made it work.

    For anyone who wants to know.

    1. Create new mouse trigger
    2. use Applescript code
    Code:
    tell application "System Events" to keystroke (ASCII character ##) using command down
    and "Run as Applescript"
    3. input ASCII character
    • 28 for left
    • 29 for right
    • 30 for up
    • 31 for down
    (at least, that's for my Macbook keyboard, I wonder if it's different for different computers)
    4. use type: Mouse Exited (mouse entered doesn't seem to work for me)
    and then the respective sides/corners, whatever.

    it works for me, although i have found the mouse triggers to be a little buggy for me in the past... we'll have to see.

    EDIT: it only seems to work when the trigger window is open, which is the bug that always has happened to me with this type of trigger... any insight?
     

Share This Page