Doubts About Running Applescript On Background

Discussion in 'Mac Programming' started by DonK KijotE, Mar 25, 2013.

  1. DonK KijotE macrumors newbie

    Mar 25, 2013
    Madrid / Spain

    I'm writing a little Applescript which waits for a window to open in order to close it automatically.

    The things is, how can I wait for the window to open? I don't want to run an endless loop which checks for a window with a certain title...

    Could anyone give me some directions on how to achieve this in the most efficient way?

    Thanks on beforehand, any help would be appreciated!

  2. ArtOfWarfare macrumors G3


    Nov 26, 2007
    What window are you waiting for to open?

    If your Applescript is opening the window, then I see no issue with just inserting a 0.3 delay after opening the window and having it close the window at that point... I know I've done exactly that before.
  3. DonK KijotE, Mar 26, 2013
    Last edited: Mar 26, 2013

    DonK KijotE thread starter macrumors newbie

    Mar 25, 2013
    Madrid / Spain
    The window is opened by another application.

    This window will appear when a user clicks a certain button so, how wait for that without using 100% cpu ?

    For testing purposes I put my code into an endless repeat loop and it works, but cycling endlessly through the script is nor efficient nor elegant IMO.

    I hope I clarified the script scenario a bit better this time.

    Just in case someone thinks I just want someone to code for me that's not the case. Any hints on a workaround/solution will be appreciated, I will investigate further on by myself and update this post so it works as a future reference for others :)

    Thanks again!

    Current Loop Code:

    Window_Title and Target_Process are just substitutes for the real values, as I wouldn't like to give any hints on what I'm working on... Don't wan't any "idea thieves" buzzing around :p
  4. Mark FX macrumors regular

    Mark FX

    Nov 18, 2011
    West Sussex, UK
    Is your Aplescript run once or is it a stay open Applescript ?

    If its a stay open Applescript then you could use an on idle Handler.

    on idle
        -- perform periodic tests
        return 1 -- return the number of seconds between the next on idle call
    end idle
    Regards Mark
  5. Sayer macrumors 6502a


    Jan 4, 2002
    Austin, TX
    Pay for the software that is periodically popping up a window asking you to pay for it periodically will make it go away.
  6. DonK KijotE thread starter macrumors newbie

    Mar 25, 2013
    Madrid / Spain
    Mark, I understand the "on idle" will start executing if I don't do anything on the system right ?

    The thing is I want to perform the routine above explained only when I click a certain button in the software, it's precisely when it's idle that I don't want it to do anything, just wait for me to click and open the referred window...

    If I'm not understanding your point correctly let me know :)

    Thanks on beforehand!

    I see the user who posted right after you and I don't even know what he's talking about...

Share This Page