Resolved Information-filler script

Discussion in 'Mac Programming' started by jslagteren, Sep 28, 2016.

  1. jslagteren macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #1
    Okay, so I have this autohotkey script that I'd like converted to an applescript
    It is my understanding that Applescript is used on Automator
    Here is the script that I use for autohotkey on windows

    !x::SendInput Text Text{tab}Text@gmail.com{tab}numbers{tab}text numbers{tab}{tab}{tab}text{tab}numbers{tab}keystroke{tab}{tab}keystroke{tab}numbers{tab}numbers{tab}numbers{tab}numbers

    So basically it writes some text, presses tab, writes some more text with a @ and ., presses tab, writes some numbers and so on, then it presses one key, and so on and so on.
    It also has an activation key so that when I hold Alt and press X the script goes off

    How would could I turn this into an applescript that works for mac?

    Also, if it is possible to makes this into a program that I can send to others, without them being able to look at the script or edit it, it would be great

    Thanks in advance :)
     
  2. freiheit macrumors 6502a

    Joined:
    Jul 20, 2004
    Location:
    California
    #2
    I am not great with AppleScript but this one seems fairly straightforward, just passing text around. I am unsure if the key trigger thing would work in AppleScript, though. I'll have to defer to someone with more AppleScript knowledge on how to do it right.

    As to the question of making it as a program, yes the built-in AppleScript Editor on MacOS can save your script as either a script or a program.
     
  3. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #3
    Okay, thanks for the reply :)

    If the key trigger thing doesn't work in AppleScript, maybe there would be another trigger that could be used?
    As long as it is quick and easy, it should be alright.

    Maybe you could elaborate on how to pass the text around, and how I use the tab key in AppleScript, etc.?
     
  4. kryten2, Sep 29, 2016
    Last edited: Sep 29, 2016

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    System Events can do this. You can use the keystroke and key code commands from the Processes Suite. You can add a shortcut to an Automator Service or use something like Keyboard Maestro to execute scripts.

    Examples using TextEdit :

    Code:
    tell application "TextEdit" to activate
    tell application "System Events"
        tell process "TextEdit"
            set frontmost to true
            repeat 5 times
                keystroke tab
                keystroke "Fun"
                key code 48
                key code {3, 32, 45} using shift down
                keystroke return
            end repeat
        end tell
    end tell
    
    --or
    
    tell application "TextEdit" to activate
    tell application "System Events"
       tell process "TextEdit"
           set frontmost to true
           keystroke "Text Text   Text@gmail.com   0123   Text 0123           Text       0123   A       B   0123   0123   0123   0123"
       end tell
    end tell
    
    Info : https://macosxautomation.com/automator/tutorial-02.html - https://www.keyboardmaestro.com/main/
     
  5. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #5
    The thing is that I'd like to do this for a website, but it shows up on TextEditor. It was meant for a quick checkout with my information.

    Any way to make this happen?
     
  6. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
  7. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #7
    I've done some more research, and it seems that automator is not able to write text on a website.

    My idea was to write some information on a shopping checkout, so it would write my name, address, e-mail, etc, and since I sometimes buy from Supreme where their products are sold out in minutes, it would give me a better chance of getting the product.

    If this is not possible with automator, do you know any other way I could make a program that does this?
     
  8. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #8
    Not always 100% true. A lot depends on the page and how it's structured. Can you give us a URL to look at?
     
  9. superscape, Oct 6, 2016
    Last edited: Oct 7, 2016

    superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #9

    ...for example, if the web page looked like this extremely simple example:

    Code:
    <html>
    <body>
        Field: <input type="text" id="field1">
    </body>
    </html>
    
    ...then the unholy combination of AppleScript and JavaScript below would do the job:

    Code:
    tell application "Safari"
        tell front document
            do JavaScript "document.getElementById('field1').value='blah'"
        end tell
    end tell
    
    And, of course, you can execute AppleScript from Automator. Although, as I said, how successful you will be depends very much on how the HTML is written. Also, bear in mind that even if it does work, future changes to the web page may break your script.

    Another course of action you could take is to ask the site owners whether they have an official API you could use. This would be the best route to take, if it's available.
     
  10. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #10
    supremenewyork.com/checkout

    This is the website, you will have to place something in your cart to go to the checkout
    --- Post Merged, Oct 7, 2016 ---
    I was thinking that you could copy something to your clipboard, and then paste it in the right field, then it copies something else to the clipboard and pastes that to the right field.

    So maybe in the first one, it would press tab to go to field 1, then the second time it should paste, it would press tab twice so it would go to field 2.

    Would something like this be possible?
     
  11. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #11
    Possibly, but I wouldn't do it that way except as a last resort. Attempting to mimic user behaviour e.g. mouse clicks, key presses is usually the last resort. It's notoriously rickety and usually the least good way. That said, sometimes its your only option.

    If you have the page you sent me open then something like this should get you started:

    Code:
    tell application "Safari"
       tell front document
           do JavaScript "document.getElementById('order_billing_name').value='John Doe'"
       end tell
    end tell
    
    The key is to have a good poke around at the HTML source code, then figure out the JavaScript you need to fill in the elements. I'll leave that as an exercise for you! ;-)
     
  12. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #12
    As someone said you can use System Events to simulate keystrokes if there is really no other way...e.g.

    Code:
    tell application "System Events"
        keystroke "Hello World"
    end tell
    
    You can then make that a service and trigger it from a hotkey or from the services menu. You can make it a service via Automator but maybe there is an easier way as well.
     
  13. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #13
    Thank you both, now how would I save this as a program as I mentioned earlier,

    and with the script by superscape, how would I go about changing the country, card type, and dates?

    How do I make it a service via Automator, cqexbesd?
    --- Post Merged, Oct 8, 2016 ---
    and with the script by cqexbesd, would it be possible to open safari while doing this?
    So that it opens safari and then writes the keystrokes?
    --- Post Merged, Oct 8, 2016 ---
    Okay, so I already figured this part out :D
     
  14. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #14
    Okay, I figured it all out.

    I only have a couple of things that I'd like improved if possible.
    First, I have used keyboard maestro for the trigger, but it would be more convenient if I could trigger the script with no 3rd party application, so is there a way to do this?

    Second, even though I saved the script as an application, I see that it is possible to find the script inside of the application, by double-clicking on it, then > Show Package Contents > Contents > Resources > Scripts > main.scpt.
    Is there anyway to hide the contents of my application, so that others can't look at the script?

    Thanks again :)
     
  15. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #15
    You should be able to trigger it via the system preferences -> keyboard -> shortcuts but you may have to make it a service.

    Anything can be de-compiled though you may be able to obfuscate it to make the process frustrating. If there is a run-only option that might help, otherwise Google.
     
  16. jslagteren thread starter macrumors newbie

    jslagteren

    Joined:
    Sep 28, 2016
    #16
    Thanks, everything worked :)
     

Share This Page